练兵接口调整,新增获得宝箱和战报
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { COUNTER } from './../consts';
|
||||
import { CounterModel } from './Counter';
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
|
||||
@prop({ required: true })
|
||||
id: number;//捐献类型id
|
||||
}
|
||||
|
||||
export default class Donation extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
donateFund: number;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
hisDonateFund: number; //历史捐赠最高
|
||||
|
||||
@prop({ required: true, type: Report, default:[] })
|
||||
reports: Array<Report>;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
refTime: number;
|
||||
|
||||
public static async createDonation(guildCode: string, lean = true) {
|
||||
const doc = new Donation();
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:doc}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getDonation(guildCode: string, select?: string, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOne({ guildCode }).select(select).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async donation(guildCode: string, donateFund: number, report: Report, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$inc:{ donateFund, hisDonateFund: donateFund }, $push:{ reports: report}}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const DonationModel = getModelForClass(Donation);
|
||||
|
||||
export interface DonationType extends Pick<DocumentType<Donation>, keyof Donation>{}
|
||||
export type DonationUpdateParam = Partial<DonationType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user