aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/Stat.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/Stat.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/Stat.ts')
-rw-r--r--src/lib/models/Stat.ts52
1 files changed, 15 insertions, 37 deletions
diff --git a/src/lib/models/Stat.ts b/src/lib/models/Stat.ts
index 0059898..89fc00f 100644
--- a/src/lib/models/Stat.ts
+++ b/src/lib/models/Stat.ts
@@ -1,56 +1,34 @@
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
-import { NEVER_USED } from './__helpers';
+import { jsonBigint } from './__helpers';
+
+type Environment = 'production' | 'development' | 'beta';
export interface StatModel {
- environment: 'production' | 'development' | 'beta';
+ environment: Environment;
commandsUsed: bigint;
}
export interface StatModelCreationAttributes {
- environment: 'production' | 'development' | 'beta';
+ environment: Environment;
commandsUsed?: bigint;
}
-export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> implements StatModel {
- /**
- * The bot's environment.
- */
- public get environment(): 'production' | 'development' | 'beta' {
- throw new Error(NEVER_USED);
- }
- public set environment(_: 'production' | 'development' | 'beta') {
- throw new Error(NEVER_USED);
- }
+// declaration merging so that the fields don't override Sequelize's getters
+export interface Stat {
+ /** The bot's environment. */
+ environment: Environment;
- /**
- * The number of commands used
- */
- public get commandsUsed(): bigint {
- throw new Error(NEVER_USED);
- }
- public set commandsUsed(_: bigint) {
- throw new Error(NEVER_USED);
- }
+ /** The number of commands used */
+ commandsUsed: bigint;
+}
+export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> implements StatModel {
public static initModel(sequelize: Sequelize): void {
Stat.init(
{
- environment: {
- type: DataTypes.STRING,
- primaryKey: true
- },
- commandsUsed: {
- type: DataTypes.TEXT,
- allowNull: false,
- get: function (): bigint {
- return BigInt(this.getDataValue('commandsUsed') as unknown as string);
- },
- set: function (val: bigint) {
- return this.setDataValue('commandsUsed', `${val}` as any);
- },
- defaultValue: '0'
- }
+ environment: { type: DataTypes.STRING, primaryKey: true },
+ commandsUsed: jsonBigint('commandsUsed')
},
{ sequelize }
);