3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Hotfix 14

This commit is contained in:
Dragory 2021-08-19 00:55:45 +03:00
parent 8da47e53e6
commit 9244ee54a7
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1,4 +1,4 @@
import { getRepository, In, Repository } from "typeorm";
import { getRepository, In, InsertResult, Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
import { CaseTypes } from "./CaseTypes";
import { connection } from "./db";
@ -116,13 +116,30 @@ export class GuildCases extends BaseGuildRepository {
);
}
async create(data): Promise<Case> {
const result = await this.cases.insert({
...data,
guild_id: this.guildId,
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`,
});
async createInternal(data): Promise<InsertResult> {
return this.cases
.insert({
...data,
guild_id: this.guildId,
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`,
})
.catch(err => {
if (err?.code === "ER_DUP_ENTRY") {
if (data.audit_log_id) {
console.warn(`Tried to insert case with duplicate audit_log_id`);
return this.createInternal({
...data,
audit_log_id: undefined,
});
}
}
throw err;
});
}
async create(data): Promise<Case> {
const result = await this.createInternal(data);
return (await this.find(result.identifiers[0].id))!;
}