import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose"; import SequenceFactory from "mongoose-sequence"; import { hasMigrated } from "@dbconfig"; import { IUser } from "./user"; const AutoIncrement = SequenceFactory(mongoose); export interface IPrivMsg { _id: number; from: PopulatedDoc; to: PopulatedDoc; subject: string; content: string; sentAt: Date; read: boolean; deletedBy: { sender: boolean; recipient: boolean; }; } const PMSchema = new mongoose.Schema({ _id: { type: Number }, from: { type: Number, ref: "User", }, to: { type: Number, ref: "User", }, subject: { type: String }, content: { type: String }, sentAt: { type: Date, default: new Date(), }, read: { type: Boolean, default: false, }, deletedBy: { sender: { type: Boolean, default: false, }, recipient: { type: Boolean, default: false, }, }, }); hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" }); export const PrivMsg: Model = /* mongoose.models.PrivMsg || */ mongoose.model( "PrivMsg", PMSchema, "private_messages", );