task-svr/src/models/LotteryRecord.ts
CounterFire2023 7d3cd73afc reformat code
2024-01-17 11:07:48 +08:00

37 lines
1000 B
TypeScript

import { dbconn } from 'decorators/dbconn'
import { getModelForClass, index, modelOptions, mongoose, prop } from '@typegoose/typegoose'
import { Severity } from '@typegoose/typegoose/lib/internal/constants'
import { BaseModule } from './Base'
/**
* 用户抽奖记录
*/
@dbconn()
@index({ user: 1, activity: 1 }, { unique: false })
@index({ user: 1, activity: 1, dateTag: 1 }, { unique: false })
@modelOptions({
schemaOptions: { collection: 'lottery_record', timestamps: true },
options: { allowMixed: Severity.ALLOW },
})
class LotteryRecordClass extends BaseModule {
@prop()
public user: string
@prop()
public activity: string
@prop()
public dateTag: string
@prop()
public reward?: string
@prop({ default: 0 })
public amount: number
public toJson() {
return {
day: this.dateTag,
id: this.reward,
amount: this.amount,
}
}
}
export const LotteryRecord = getModelForClass(LotteryRecordClass, { existingConnection: LotteryRecordClass['db'] })