捐献
This commit is contained in:
+12
-3
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
@@ -29,9 +30,13 @@ export default class Donation extends BaseModel {
|
||||
@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);
|
||||
@prop({ required: true })
|
||||
donationLv: number;
|
||||
|
||||
public static async createDonation(guildCode: string, donationLv: number, lean = true) {
|
||||
const doc = new DonationModel();
|
||||
const update = Object.assign(doc.toJSON(), {refTime: nowSeconds(), reports:[], hisDonateFund: 0, donateFund: 0, donationLv});
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:update}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -45,6 +50,10 @@ export default class Donation extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateDonation(guildCode: string, update: DonationUpdateParam, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, { $set:update }, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const DonationModel = getModelForClass(Donation);
|
||||
|
||||
Reference in New Issue
Block a user