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 }) sendName: string; public static async addMails( mails: Array) { await MailModel.insertMany(mails); } public static async addMail(params:{roleId: string, goods: Array, sendName: string, mailId: number, sendTime?: number}) { 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, keyof Mail> { };