aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/ActivePunishment.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/ActivePunishment.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/ActivePunishment.ts')
-rw-r--r--src/lib/models/ActivePunishment.ts136
1 files changed, 29 insertions, 107 deletions
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<ActivePunishmentModel, ActivePunishmentModelCreationAttributes>
- 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<ActivePunishmentModel, ActivePunishmentModelCreationAttributes>
+ 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 }
);