aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/ModLog.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-27 19:26:52 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-27 19:26:52 -0400
commit38f488528ba96e8445f29c9fe24131930f03a697 (patch)
treefd87eb69a0f785739e51077aa3b94921fa9be8ee /src/lib/models/ModLog.ts
parent43dadce8b744a43b86cc3febba1046d714cdafcb (diff)
downloadtanzanite-38f488528ba96e8445f29c9fe24131930f03a697.tar.gz
tanzanite-38f488528ba96e8445f29c9fe24131930f03a697.tar.bz2
tanzanite-38f488528ba96e8445f29c9fe24131930f03a697.zip
use declaration merging for models and clean them up
Diffstat (limited to 'src/lib/models/ModLog.ts')
-rw-r--r--src/lib/models/ModLog.ts188
1 files changed, 36 insertions, 152 deletions
diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts
index 3675649..0151cf6 100644
--- a/src/lib/models/ModLog.ts
+++ b/src/lib/models/ModLog.ts
@@ -2,7 +2,7 @@ import { Snowflake } from 'discord.js';
import { nanoid } from 'nanoid';
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
-import { jsonParseGet, jsonParseSet, NEVER_USED } from './__helpers';
+import { jsonBoolean } from './__helpers';
export enum ModLogType {
PERM_BAN = 'PERM_BAN',
@@ -47,171 +47,55 @@ export interface ModLogModelCreationAttributes {
hidden?: boolean;
}
-export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
- /**
- * The primary key of the modlog entry.
- */
- public get id(): string {
- throw new Error(NEVER_USED);
- }
- public set id(_: string) {
- throw new Error(NEVER_USED);
- }
+// declaration merging so that the fields don't override Sequelize's getters
+export interface ModLog {
+ /** The primary key of the modlog entry. */
+ id: string;
- /**
- * The type of punishment.
- */
- public get type(): ModLogType {
- throw new Error(NEVER_USED);
- }
- public set type(_: ModLogType) {
- throw new Error(NEVER_USED);
- }
+ /** The type of punishment. */
+ type: ModLogType;
- /**
- * The user being punished.
- */
- public get user(): Snowflake {
- throw new Error(NEVER_USED);
- }
- public set user(_: Snowflake) {
- throw new Error(NEVER_USED);
- }
+ /** The user being punished. */
+ user: Snowflake;
- /**
- * The user carrying out the punishment.
- */
- public get moderator(): Snowflake {
- throw new Error(NEVER_USED);
- }
- public set moderator(_: Snowflake) {
- throw new Error(NEVER_USED);
- }
+ /** The user carrying out the punishment. */
+ moderator: Snowflake;
- /**
- * The reason the user is getting punished
- */
- public get reason(): string | null {
- throw new Error(NEVER_USED);
- }
- public set reason(_: string | null) {
- throw new Error(NEVER_USED);
- }
+ /** The reason the user is getting punished. */
+ reason: string | null;
- /**
- * The amount of time the user is getting punished for.
- */
- public get duration(): number | null {
- throw new Error(NEVER_USED);
- }
- public set duration(_: number | null) {
- throw new Error(NEVER_USED);
- }
+ /** The amount of time the user is getting punished for. */
+ duration: number | null;
- /**
- * The guild the user is getting punished in.
- */
- public get guild(): Snowflake {
- throw new Error(NEVER_USED);
- }
- public set guild(_: Snowflake) {
- throw new Error(NEVER_USED);
- }
+ /** The guild the user is getting punished in. */
+ guild: Snowflake;
- /**
- * Evidence of what the user is getting punished for.
- */
- public get evidence(): string {
- throw new Error(NEVER_USED);
- }
- public set evidence(_: string) {
- throw new Error(NEVER_USED);
- }
+ /** Evidence of what the user is getting punished for. */
+ evidence: string;
- /**
- * Not an actual modlog just used so a punishment entry can be made
- */
- public get pseudo(): boolean {
- throw new Error(NEVER_USED);
- }
- public set pseudo(_: boolean) {
- throw new Error(NEVER_USED);
- }
+ /** Not an actual modlog just used so a punishment entry can be made. */
+ pseudo: boolean;
- /**
- * Hides from the modlog command unless show hidden is specified.
- */
- public get hidden(): boolean {
- throw new Error(NEVER_USED);
- }
- public set hidden(_: boolean) {
- throw new Error(NEVER_USED);
- }
+ /** Hides from the modlog command unless show hidden is specified. */
+ hidden: boolean;
+}
+export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
public static initModel(sequelize: Sequelize): void {
ModLog.init(
{
- id: {
- type: DataTypes.STRING,
- primaryKey: true,
- allowNull: false,
- defaultValue: nanoid
- },
- type: {
- type: DataTypes.STRING, //# This is not an enum because of a sequelize issue: https://github.com/sequelize/sequelize/issues/2554
- allowNull: false
- },
- user: {
- type: DataTypes.STRING,
- allowNull: false
- },
- moderator: {
- type: DataTypes.STRING,
- allowNull: false
- },
- duration: {
- type: DataTypes.STRING,
- allowNull: true
- },
- reason: {
- type: DataTypes.TEXT,
- allowNull: true
- },
- guild: {
- type: DataTypes.STRING,
- references: {
- model: 'Guilds',
- key: 'id'
- }
- },
- evidence: {
- type: DataTypes.TEXT,
- allowNull: true
- },
- pseudo: {
- type: DataTypes.STRING,
- get: function (): boolean {
- return jsonParseGet.call(this, 'pseudo');
- },
- set: function (val: boolean) {
- return jsonParseSet.call(this, 'pseudo', val);
- },
- allowNull: false,
- defaultValue: 'false'
- },
- hidden: {
- type: DataTypes.STRING,
- get: function (): boolean {
- return jsonParseGet.call(this, 'hidden');
- },
- set: function (val: boolean) {
- return jsonParseSet.call(this, 'hidden', val);
- },
- allowNull: false,
- defaultValue: 'false'
- }
+ id: { type: DataTypes.STRING, primaryKey: true, allowNull: false, defaultValue: nanoid },
+ type: { type: DataTypes.STRING, allowNull: false }, //# This is not an enum because of a sequelize issue: https://github.com/sequelize/sequelize/issues/2554
+ user: { type: DataTypes.STRING, allowNull: false },
+ moderator: { type: DataTypes.STRING, allowNull: false },
+ duration: { type: DataTypes.STRING, allowNull: true },
+ reason: { type: DataTypes.TEXT, allowNull: true },
+ guild: { type: DataTypes.STRING, references: { model: 'Guilds', key: 'id' } },
+ evidence: { type: DataTypes.TEXT, allowNull: true },
+ pseudo: jsonBoolean('pseudo'),
+ hidden: jsonBoolean('hidden')
},
- { sequelize: sequelize }
+ { sequelize }
);
}
}