Files
ZYZ/shared/db/BattleDrop.ts
2022-10-24 18:46:24 +08:00

45 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 战斗记录接口
*/
@index({ roleId: 1, battleId: 1, gid: 1 })
export default class BattleDrop extends BaseModel {
@prop({ required: true })
roleId: string; // 角色 id
@prop({ required: true })
battleId: number; // 关卡 id
@prop({ required: true })
gid: number; // 关卡 id
@prop({ required: true, default: 0 })
getNum: number; // 获取次数当allNum超过配置次数重置
@prop({ required: true, default: 0 })
allNum: number; // 全部次数,当超过配置次数重置
@prop({ required: true, default: 0 })
getSum: number; // 获取道具的全部次数
@prop({ required: true, default: 0 })
allSum: number; // 全部全部次数,不重置
public static async findByGid(roleId: string, battleId: number, gid: number, lean = true) {
const result: BattleDropType = await BattleDropModel.findOneAndUpdate({ roleId, battleId, gid}, {}, {new: true, upsert: true}).lean(lean);
return result;
}
public static async updateByGid(roleId: string, battleId: number, gid: number, params: {getNum: number, allNum: number, getSum: number, allSum: number}, lean = true) {
const result: BattleDropType = await BattleDropModel.findOneAndUpdate({roleId, battleId, gid}, {$set: params}).lean(lean);
return result;
}
public static async deleteAccount(roleId: string) {
let result = await BattleDropModel.deleteMany({roleId});
return result;
}
}
export const BattleDropModel = getModelForClass(BattleDrop);
export interface BattleDropType extends Pick<DocumentType<BattleDrop>, keyof BattleDrop>{}