49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
|
|
|
/**
|
|
* 远征记录
|
|
*/
|
|
@index({ roleId: 1 })
|
|
|
|
export default class ExpeditionPoint extends BaseModel {
|
|
@prop({ required: true, default: '' })
|
|
roleId: string; // 角色 id
|
|
|
|
@prop({ required: true, default: 0 })
|
|
pointCost: number; // 消耗点数
|
|
@prop({ required: true, default: false })
|
|
completed: boolean; // 本轮奖励是否完成
|
|
@prop({ required: true, default: [] })
|
|
rewards: Array<{point: number, reward: string, received:boolean, recTime: Date}>; // 领取记录
|
|
|
|
public static async getExpeditionPoint(roleId: string, lean = true) {
|
|
const result = await ExpeditionPointModel.findOne({ roleId, completed: false }).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async updatePointStatus(roleId: string, point: number, reward: string, lean = true) {
|
|
const result = await ExpeditionPointModel.findOneAndUpdate(
|
|
{ roleId, completed: false },
|
|
{ $set: { pointCost: point }, $push: {rewards:{point, reward, received: true, recTime: new Date()}}},
|
|
{ new: true, upsert: true }
|
|
).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async completeStatus(roleId: string, lean = true) {
|
|
const result = await ExpeditionPointModel.findOneAndUpdate(
|
|
{ roleId, completed: false },
|
|
{ $set: {completed: true } }
|
|
).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async deleteAccount(roleId: string, lean = true) {
|
|
let result = await ExpeditionPointModel.deleteMany({roleId}).lean(lean);
|
|
return result||{};
|
|
}
|
|
}
|
|
|
|
export const ExpeditionPointModel = getModelForClass(ExpeditionPoint);
|