mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Rename ModActions to Cases
This commit is contained in:
parent
62dfc80a0e
commit
e6f296381e
7 changed files with 154 additions and 152 deletions
|
@ -1,4 +1,4 @@
|
|||
export enum ModActionType {
|
||||
export enum CaseType {
|
||||
Ban = 1,
|
||||
Unban,
|
||||
Note,
|
76
src/data/GuildCases.ts
Normal file
76
src/data/GuildCases.ts
Normal file
|
@ -0,0 +1,76 @@
|
|||
import * as knex from "../knex";
|
||||
import Case from "../models/Case";
|
||||
|
||||
export class GuildCases {
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
async find(id: number): Promise<Case> {
|
||||
const result = await knex("cases")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("id", id)
|
||||
.first();
|
||||
|
||||
return result ? new Case(result) : null;
|
||||
}
|
||||
|
||||
async findByCaseNumber(caseNumber: number): Promise<Case> {
|
||||
const result = await knex("cases")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("case_number", caseNumber)
|
||||
.first();
|
||||
|
||||
return result ? new Case(result) : null;
|
||||
}
|
||||
|
||||
async getCaseNotes(caseId: number): Promise<Case[]> {
|
||||
const results = await knex("case_notes")
|
||||
.where("case_id", caseId)
|
||||
.select();
|
||||
|
||||
return results.map(r => new Case(r));
|
||||
}
|
||||
|
||||
async getByUserId(userId: string): Promise<Case[]> {
|
||||
const results = await knex("cases")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("user_id", userId)
|
||||
.select();
|
||||
|
||||
return results.map(r => new Case(r));
|
||||
}
|
||||
|
||||
async create(data): Promise<number> {
|
||||
return knex
|
||||
.insert({
|
||||
...data,
|
||||
guild_id: this.guildId,
|
||||
case_number: knex.raw(
|
||||
"(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ?)",
|
||||
this.guildId
|
||||
)
|
||||
})
|
||||
.returning("id")
|
||||
.into("cases")
|
||||
.then(ids => Number(ids[0]));
|
||||
}
|
||||
|
||||
update(id, data) {
|
||||
return knex("cases")
|
||||
.where("id", id)
|
||||
.update(data);
|
||||
}
|
||||
|
||||
createNote(caseId: number, data: any) {
|
||||
return knex
|
||||
.insert({
|
||||
...data,
|
||||
case_id: caseId
|
||||
})
|
||||
.into("case_notes")
|
||||
.return();
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
import knex from "../knex";
|
||||
import ModAction from "../models/ModAction";
|
||||
|
||||
export class GuildModActions {
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
async find(id: number): Promise<ModAction> {
|
||||
const result = await knex("mod_actions")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("id", id)
|
||||
.first();
|
||||
|
||||
return result ? new ModAction(result) : null;
|
||||
}
|
||||
|
||||
async findByCaseNumber(caseNumber: number): Promise<ModAction> {
|
||||
const result = await knex("mod_actions")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("case_number", caseNumber)
|
||||
.first();
|
||||
|
||||
return result ? new ModAction(result) : null;
|
||||
}
|
||||
|
||||
async getActionNotes(actionId: number): Promise<ModAction[]> {
|
||||
const results = await knex("mod_action_notes")
|
||||
.where("mod_action_id", actionId)
|
||||
.select();
|
||||
|
||||
return results.map(r => new ModAction(r));
|
||||
}
|
||||
|
||||
async getByUserId(userId: string): Promise<ModAction[]> {
|
||||
const results = await knex("mod_actions")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("user_id", userId)
|
||||
.select();
|
||||
|
||||
return results.map(r => new ModAction(r));
|
||||
}
|
||||
|
||||
async create(data): Promise<number> {
|
||||
return knex
|
||||
.insert({
|
||||
...data,
|
||||
guild_id: this.guildId,
|
||||
case_number: knex.raw(
|
||||
"(SELECT IFNULL(MAX(case_number)+1, 1) FROM mod_actions AS ma2 WHERE guild_id = ?)",
|
||||
this.guildId
|
||||
)
|
||||
})
|
||||
.returning("id")
|
||||
.into("mod_actions")
|
||||
.then(ids => Number(ids[0]));
|
||||
}
|
||||
|
||||
update(id, data) {
|
||||
return knex("mod_actions")
|
||||
.where("id", id)
|
||||
.update(data);
|
||||
}
|
||||
|
||||
createNote(modActionId: number, data: any) {
|
||||
return knex
|
||||
.insert({
|
||||
...data,
|
||||
mod_action_id: modActionId
|
||||
})
|
||||
.into("mod_action_notes")
|
||||
.return();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import knex from "../knex";
|
||||
import * as knex from "../knex";
|
||||
import * as moment from "moment-timezone";
|
||||
import Mute from "../models/Mute";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue