Add AutoKickConfig to database
This commit is contained in:
parent
bfbf386eeb
commit
8e16a4fda6
5 changed files with 82 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
DROP TABLE auto_kick_config;
|
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE auto_kick_config (
|
||||
Id varchar(255) NOT NULL,
|
||||
WhenCreated datetime NOT NULL,
|
||||
WhenUpdated datetime NOT NULL,
|
||||
ServerId varchar(255) NOT NULL,
|
||||
RoleId varchar(255) NOT NULL,
|
||||
KickTime int NOT NULL,
|
||||
NoticeTime int NULL,
|
||||
NoticeChannelId varchar(255) NULL
|
||||
);
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE auto_kick_config
|
||||
ADD PRIMARY KEY (Id);
|
50
src/database/entities/AutoKickConfig.ts
Normal file
50
src/database/entities/AutoKickConfig.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import {Column, Entity} from "typeorm";
|
||||
import AppDataSource from "../dataSources/appDataSource";
|
||||
import BaseEntity from "../../contracts/BaseEntity";
|
||||
|
||||
@Entity()
|
||||
export default class AutoKickConfig extends BaseEntity {
|
||||
constructor(serverId: string, roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
||||
super();
|
||||
|
||||
this.ServerId = serverId;
|
||||
this.RoleId = roleId;
|
||||
this.KickTime = kickTime;
|
||||
this.NoticeTime = noticeTime;
|
||||
this.NoticeChannelId = noticeChannelId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
ServerId: string;
|
||||
|
||||
@Column()
|
||||
RoleId: string;
|
||||
|
||||
@Column({ type: "int" })
|
||||
KickTime: number;
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
NoticeTime?: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
NoticeChannelId?: string;
|
||||
|
||||
public UpdateBasicDetails(roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
||||
this.RoleId = roleId;
|
||||
this.KickTime = kickTime;
|
||||
this.NoticeTime = noticeTime;
|
||||
this.NoticeChannelId = noticeChannelId;
|
||||
}
|
||||
|
||||
public static async FetchOneByServerIdAndRoleId(serverId: string, roleId: string): Promise<AutoKickConfig | null> {
|
||||
const repository = AppDataSource.getRepository(AutoKickConfig);
|
||||
|
||||
const query = repository
|
||||
.createQueryBuilder("config")
|
||||
.where("config.serverId = :serverId", { serverId })
|
||||
.andWhere("config.roleId = :roleId", { roleId })
|
||||
.getOne();
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import MigrationHelper from "../../../helpers/MigrationHelper";
|
||||
|
||||
export class CreateAutoKickConfig1732973911304 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Up("1732973911304-createAutoKickConfig", "3.2.4", [
|
||||
"01-AutoKickConfig-Table",
|
||||
"02-AutoKickConfig-Key",
|
||||
], queryRunner)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Down("1732973911304-createAutoKickConfig", "3.2.4", [
|
||||
"01-AutoKickConfig",
|
||||
], queryRunner)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue