From 38f488528ba96e8445f29c9fe24131930f03a697 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 27 Oct 2021 19:26:52 -0400 Subject: use declaration merging for models and clean them up --- src/lib/models/ActivePunishment.ts | 136 ++++++++----------------------------- 1 file changed, 29 insertions(+), 107 deletions(-) (limited to 'src/lib/models/ActivePunishment.ts') diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts index 12b0cab..0ad6cd8 100644 --- a/src/lib/models/ActivePunishment.ts +++ b/src/lib/models/ActivePunishment.ts @@ -19,6 +19,7 @@ export interface ActivePunishmentModel { expires: Date | null; modlog: string; } + export interface ActivePunishmentModelCreationAttributes { id?: string; type: ActivePunishmentType; @@ -29,123 +30,44 @@ export interface ActivePunishmentModelCreationAttributes { modlog: string; } -const NEVER_USED = 'This should never be executed'; - -export class ActivePunishment - extends BaseModel - implements ActivePunishmentModel -{ - /** - * The ID of this punishment (no real use just for a primary key) - */ - 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 ActivePunishment { + /** The ID of this punishment (no real use just for a primary key) */ + id: string; - /** - * The type of punishment. - */ - public get type(): ActivePunishmentType { - throw new Error(NEVER_USED); - } - public set type(_: ActivePunishmentType) { - throw new Error(NEVER_USED); - } + /** The type of punishment. */ + type: ActivePunishmentType; - /** - * The user who is punished. - */ - public get user(): Snowflake { - throw new Error(NEVER_USED); - } - public set user(_: Snowflake) { - throw new Error(NEVER_USED); - } + /** The user who is punished. */ + user: Snowflake; - /** - * The guild they are punished in. - */ - public get guild(): Snowflake { - throw new Error(NEVER_USED); - } - public set guild(_: Snowflake) { - throw new Error(NEVER_USED); - } + /** The guild they are punished in. */ + guild: Snowflake; - /** - * Additional info about the punishment if applicable. The channel id for channel blocks and role for punishment roles. - */ - public get extraInfo(): Snowflake { - throw new Error(NEVER_USED); - } - public set extraInfo(_: Snowflake) { - throw new Error(NEVER_USED); - } + /** Additional info about the punishment if applicable. The channel id for channel blocks and role for punishment roles. */ + extraInfo: Snowflake; - /** - * The date when this punishment expires (optional). - */ - public get expires(): Date | null { - throw new Error(NEVER_USED); - } - public set expires(_: Date | null) { - throw new Error(NEVER_USED); - } + /** The date when this punishment expires (optional). */ + expires: Date | null; - /** - * The reference to the modlog entry. - */ - public get modlog(): string { - throw new Error(NEVER_USED); - } - public set modlog(_: string) { - throw new Error(NEVER_USED); - } + /** The reference to the modlog entry. */ + modlog: string; +} +export class ActivePunishment + extends BaseModel + implements ActivePunishmentModel +{ public static initModel(sequelize: Sequelize): void { ActivePunishment.init( { - id: { - type: DataTypes.STRING, - primaryKey: true, - allowNull: false, - defaultValue: nanoid - }, - type: { - type: DataTypes.STRING, - allowNull: false - }, - user: { - type: DataTypes.STRING, - allowNull: false - }, - guild: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'Guilds', - key: 'id' - } - }, - extraInfo: { - type: DataTypes.STRING, - allowNull: true - }, - expires: { - type: DataTypes.DATE, - allowNull: true - }, - modlog: { - type: DataTypes.STRING, - allowNull: true, - references: { - model: 'ModLogs', - key: 'id' - } - } + id: { type: DataTypes.STRING, primaryKey: true, allowNull: false, defaultValue: nanoid }, + type: { type: DataTypes.STRING, allowNull: false }, + user: { type: DataTypes.STRING, allowNull: false }, + guild: { type: DataTypes.STRING, allowNull: false, references: { model: 'Guilds', key: 'id' } }, + extraInfo: { type: DataTypes.STRING, allowNull: true }, + expires: { type: DataTypes.DATE, allowNull: true }, + modlog: { type: DataTypes.STRING, allowNull: true, references: { model: 'ModLogs', key: 'id' } } }, { sequelize } ); -- cgit