42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { Severity, getModelForClass, index, modelOptions, mongoose, prop } from '@typegoose/typegoose'
|
|
import { dbconn } from 'decorators/dbconn'
|
|
import { BaseModule } from './Base'
|
|
|
|
@dbconn()
|
|
@index({ user: 1 }, { unique: false })
|
|
@index({ activity: 1 }, { unique: false })
|
|
@index({ user: 1, activity: 1, type: 1 }, { unique: false })
|
|
@modelOptions({
|
|
schemaOptions: { collection: 'score_record', timestamps: true },
|
|
options: { allowMixed: Severity.ALLOW },
|
|
})
|
|
class ScoreRecordClass extends BaseModule {
|
|
@prop({ required: true })
|
|
public user: string
|
|
|
|
@prop({ required: true })
|
|
public activity: string
|
|
|
|
@prop()
|
|
public score: number
|
|
|
|
@prop()
|
|
public type: string
|
|
|
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
|
public data: any
|
|
|
|
public toJson() {
|
|
return {
|
|
user: this.user,
|
|
activity: this.activity,
|
|
score: this.score,
|
|
type: this.type,
|
|
//@ts-ignore
|
|
time: this.createdAt.getTime(),
|
|
}
|
|
}
|
|
}
|
|
|
|
export const ScoreRecord = getModelForClass(ScoreRecordClass, { existingConnection: ScoreRecordClass['db'] })
|