Hotfix 14
This commit is contained in:
parent
8da47e53e6
commit
9244ee54a7
1 changed files with 24 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { getRepository, In, Repository } from "typeorm";
|
import { getRepository, In, InsertResult, Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { CaseTypes } from "./CaseTypes";
|
import { CaseTypes } from "./CaseTypes";
|
||||||
import { connection } from "./db";
|
import { connection } from "./db";
|
||||||
|
@ -116,13 +116,30 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data): Promise<Case> {
|
async createInternal(data): Promise<InsertResult> {
|
||||||
const result = await this.cases.insert({
|
return this.cases
|
||||||
...data,
|
.insert({
|
||||||
guild_id: this.guildId,
|
...data,
|
||||||
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`,
|
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))!;
|
return (await this.find(result.identifiers[0].id))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue