48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
|
import { nowSeconds, getTodayZeroPoint } from '../pubUtils/timeUtil';
|
|
|
|
@index({ guildCode: 1 })
|
|
|
|
export default class WishPoolReport extends BaseModel {
|
|
@prop({ required: true })
|
|
guildCode: string; // 角色 id
|
|
|
|
@prop({ required: true })
|
|
dntTime: number; //捐献时间
|
|
|
|
@prop({ required: true })
|
|
wishRoleId: string; //被捐献人
|
|
|
|
@prop({ required: true })
|
|
wishRoleName: string; //捐赠人
|
|
|
|
@prop({ required: true })
|
|
goodId: number; //捐献物品
|
|
|
|
@prop({ required: true })
|
|
count: number; //捐献物品数量
|
|
|
|
@prop({ required: true })
|
|
dntRoleId: string; //捐赠人
|
|
|
|
@prop({ required: true })
|
|
dntRoleName: string; //捐赠人
|
|
|
|
public static async addReport(guildCode: string, wishRoleId: string, wishRoleName: string, dntRoleId: string, dntRoleName: string, goodId: number, count: number, lean = true) {
|
|
const doc = new WishPoolReportModel();
|
|
const report = Object.assign(doc.toJSON(), { guildCode, wishRoleId, wishRoleName, dntRoleId, dntRoleName, goodId, dntTime: nowSeconds(), count });
|
|
await WishPoolReportModel.create(report);
|
|
return report;
|
|
}
|
|
//获得day天之前的许愿池战报
|
|
public static async getReportsByTime(guildCode: string, day: number, lean = true) {
|
|
let time = getTodayZeroPoint() - day * 24 * 60;
|
|
const reports = await WishPoolReportModel.find({ guildCode, dntTime: {$gte: time}}).sort({ dntTime : -1 });
|
|
return reports;
|
|
}
|
|
}
|
|
|
|
export const WishPoolReportModel = getModelForClass(WishPoolReport);
|
|
|
|
export interface WishPoolReportType extends Pick<DocumentType<WishPoolReport>, keyof WishPoolReport>{} |