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: 'token_claim_record', timestamps: true }, options: { allowMixed: Severity.ALLOW }, }) class TokenClaimHistoryClass extends BaseModule { @prop({ required: true }) public user: string @prop({ required: true }) public activity: string /** * 冗余字段, 方便查找 */ @prop() public address: string @prop() public token: string @prop() public amount: number /** * 0: 待确认 * 1: 已确认 * -1: 已明确失败 */ @prop({ default: 0 }) public status: number // 转账交易hash @prop() public hash: string public static async addOne(params: Partial) { const record = new TokenClaimHistory(params) await record.save() return record } } export const TokenClaimHistory = getModelForClass(TokenClaimHistoryClass, { existingConnection: TokenClaimHistoryClass['db'], })