mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Use a model class for mod actions
This commit is contained in:
parent
47f124c7d6
commit
e9fb76f76d
3 changed files with 39 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
import knex from "../knex";
|
||||
import ModAction from "../models/ModAction";
|
||||
|
||||
export class GuildModActions {
|
||||
protected guildId: string;
|
||||
|
@ -7,34 +8,42 @@ export class GuildModActions {
|
|||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
find(id: number) {
|
||||
return knex("mod_actions")
|
||||
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;
|
||||
}
|
||||
|
||||
findByCaseNumber(caseNumber: number) {
|
||||
return knex("mod_actions")
|
||||
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;
|
||||
}
|
||||
|
||||
getActionNotes(actionId: number) {
|
||||
return knex("mod_action_notes")
|
||||
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));
|
||||
}
|
||||
|
||||
getByUserId(userId: string) {
|
||||
return knex("mod_actions")
|
||||
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));
|
||||
}
|
||||
|
||||
create(data) {
|
||||
async create(data): Promise<number> {
|
||||
return knex
|
||||
.insert({
|
||||
...data,
|
||||
|
|
14
src/models/ModAction.ts
Normal file
14
src/models/ModAction.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import Model from "./Model";
|
||||
|
||||
export default class ModAction extends Model {
|
||||
public id: number;
|
||||
public guild_id: string;
|
||||
public case_number: number;
|
||||
public user_id: string;
|
||||
public user_name: string;
|
||||
public mod_id: string;
|
||||
public mod_name: string;
|
||||
public action_type: number;
|
||||
public audit_log_id: string;
|
||||
public created_at: string;
|
||||
}
|
7
src/models/Model.ts
Normal file
7
src/models/Model.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export default class Model {
|
||||
constructor(props) {
|
||||
for (const key in props) {
|
||||
this[key] = props[key];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue