Files
ZYZ/shared/db/Mail.ts
mamengke01 f836d6586a 捐献所
2021-02-03 10:39:43 +08:00

46 lines
1.3 KiB
TypeScript

import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { nowSeconds } from '../pubUtils/timeUtil';
class RewardInter {
id: number;
count: number;
}
@index({ roleId: 1 })
export default class Mail extends BaseModel {
@prop({ required: true })
roleId: string;
@prop({ required: true })
mailId: number;
@prop({ required: true, type:RewardInter, default: [], _id: false})
goods: RewardInter[];
@prop({ required: true, default: nowSeconds() })
sendTime: number;
@prop({ required: true, default: "" })
sendName: string;
@prop({ required: true })
content: string;
@prop({ required: true, default: 0 })
status: number;
public static async addMails(mails: Array<MailType>) {
await MailModel.insertMany(mails);
}
public static async addMail(params:{ roleId: string, goods: Array<RewardInter>, sendName: string, mailId: number, sendTime?: number, content?:string }) {
const doc = new MailModel();
const mail = Object.assign(doc.toJSON(), params);
await MailModel.create(mail);
return mail;
}
}
export const MailModel = getModelForClass(Mail);
export interface MailType extends Pick<DocumentType<Mail>, keyof Mail> { };