43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { COUNTER } from '../consts/consts';
|
|
import { CounterModel } from './Counter';
|
|
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
|
import { timeStamp } from 'console';
|
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
|
|
|
|
@index({ roleId: 1, hid: 1, eid: 1 })
|
|
@index({ seqId: 1 })
|
|
|
|
export default class BattleRecord extends BaseModel {
|
|
@prop({ required: true })
|
|
roleId: string; // 角色 id
|
|
@prop({ required: true })
|
|
roleName: string; // 角色名称
|
|
|
|
@prop({ required: true })
|
|
battleCode: string; // 关卡记录唯一标识
|
|
@prop({ required: true })
|
|
battleId: number; // 关卡 id
|
|
@prop({ required: true })
|
|
status: number; // 关卡状态 0-挑战中 1-挑战成功 2-挑战失败
|
|
@prop({ required: true })
|
|
record: { // 使用的武将等记录
|
|
heroes: Array <number>; // 武将id
|
|
};
|
|
|
|
|
|
public static async getBattleRecordByCode(battleCode: string, lean = true) {
|
|
const result = await BattleRecordModel.findOne({ battleCode }).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async updateBattleRecordByCode( battleCode: string, params: object, lean = true) {
|
|
const result = await BattleRecordModel.findOneAndUpdate({ battleCode }, params, {new: true, upsert: true}).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
export const BattleRecordModel = getModelForClass(BattleRecord);
|