diff --git a/src/data/GuildCases.ts b/src/data/GuildCases.ts index e3cbc696..5ebb697f 100644 --- a/src/data/GuildCases.ts +++ b/src/data/GuildCases.ts @@ -22,8 +22,8 @@ export class GuildCases extends BaseRepository { relations: this.getRelations(), where: { guild_id: this.guildId, - id: In(ids) - } + id: In(ids), + }, }); } @@ -32,8 +32,8 @@ export class GuildCases extends BaseRepository { relations: this.getRelations(), where: { guild_id: this.guildId, - id - } + id, + }, }); } @@ -42,8 +42,21 @@ export class GuildCases extends BaseRepository { relations: this.getRelations(), where: { guild_id: this.guildId, - case_number: caseNumber - } + case_number: caseNumber, + }, + }); + } + + async findLatestByModId(modId: string): Promise { + return this.cases.findOne({ + relations: this.getRelations(), + where: { + guild_id: this.guildId, + mod_id: modId, + }, + order: { + case_number: "DESC", + }, }); } @@ -52,8 +65,8 @@ export class GuildCases extends BaseRepository { relations: this.getRelations(), where: { guild_id: this.guildId, - user_id: userId - } + user_id: userId, + }, }); } @@ -61,8 +74,8 @@ export class GuildCases extends BaseRepository { await this.cases.update( { id }, { - is_hidden: hidden - } + is_hidden: hidden, + }, ); } @@ -70,7 +83,7 @@ export class GuildCases extends BaseRepository { 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})` + case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`, }); return this.find(result.identifiers[0].id); @@ -83,7 +96,7 @@ export class GuildCases extends BaseRepository { async createNote(caseId: number, data: any): Promise { await this.caseNotes.insert({ ...data, - case_id: caseId + case_id: caseId, }); } diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index 9515edb1..b61fba2b 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -261,7 +261,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { */ @d.command(/update|updatecase/, " ") @d.permission("note") - async updateCmd(msg: Message, args: any) { + async updateSpecificCmd(msg: Message, args: { caseNumber: number; note: string }) { const theCase = await this.cases.findByCaseNumber(args.caseNumber); if (!theCase) { msg.channel.createMessage(errorMessage("Case not found")); @@ -277,6 +277,27 @@ export class ModActionsPlugin extends ZeppelinPlugin { msg.channel.createMessage(successMessage(`Case \`#${theCase.case_number}\` updated`)); } + /** + * Update the latest case + */ + @d.command(/update|updatecase/, "") + @d.permission("note") + async updateLatestCmd(msg: Message, args: { note: string }) { + const theCase = await this.cases.findLatestByModId(msg.author.id); + if (!theCase) { + msg.channel.createMessage(errorMessage("No latest case")); + return; + } + + await this.actions.fire("createCaseNote", { + caseId: theCase.id, + modId: msg.author.id, + note: args.note, + }); + + msg.channel.createMessage(successMessage(`Case \`#${theCase.case_number}\` updated`)); + } + @d.command("note", " ") @d.permission("note") async noteCmd(msg: Message, args: any) {