next/models/privMsg.ts

61 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-10-03 01:22:43 -04:00
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<IUser & Document>;
to: PopulatedDoc<IUser & Document>;
subject: string;
content: string;
sentAt: Date;
read: boolean;
deletedBy: {
sender: boolean;
recipient: boolean;
2023-10-03 01:22:43 -04:00
};
}
const PMSchema = new mongoose.Schema<IPrivMsg>({
2023-10-03 01:22:43 -04:00
_id: { type: Number },
from: {
type: Number,
2023-10-03 01:22:43 -04:00
ref: "User",
},
to: {
type: Number,
2023-10-03 01:22:43 -04:00
ref: "User",
},
subject: { type: String },
content: { type: String },
sentAt: {
type: Date,
2023-10-03 01:22:43 -04:00
default: new Date(),
},
read: {
type: Boolean,
2023-10-03 01:22:43 -04:00
default: false,
},
deletedBy: {
sender: {
type: Boolean,
2023-10-03 01:22:43 -04:00
default: false,
},
recipient: {
type: Boolean,
2023-10-03 01:22:43 -04:00
default: false,
},
},
});
hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" });
2023-10-03 01:22:43 -04:00
export const PrivMsg: Model<IPrivMsg> =
/* mongoose.models.PrivMsg || */ mongoose.model(
"PrivMsg",
PMSchema,
"private_messages",
);