-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
Note.ts
50 lines (46 loc) · 1.35 KB
/
Note.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { Model, PopulatedDoc, Types } from "mongoose";
import { Schema, model, models } from "mongoose";
import type { InterfaceUser } from "./User";
export interface InterfaceNote {
_id: Types.ObjectId; // Unique identifier for the note.
content: string; // Content of the note.
createdBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who created the note.
updatedBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who last updated the note.
createdAt: Date; // Date when the note was created.
updatedAt: Date; // Date when the note was last updated.
agendaItemId: Types.ObjectId; // Reference to the agenda item associated with the note.
}
export const NoteSchema = new Schema({
content: {
type: String,
required: true,
},
createdBy: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
updatedBy: {
type: Schema.Types.ObjectId,
ref: "User",
},
createdAt: {
type: Date,
required: true,
default: Date.now,
},
updatedAt: {
type: Date,
default: Date.now,
},
agendaItemId: {
type: Schema.Types.ObjectId,
ref: "AgendaItem",
required: true,
},
});
const noteModel = (): Model<InterfaceNote> =>
model<InterfaceNote>("Note", NoteSchema);
export const NoteModel = (models.Note || noteModel()) as ReturnType<
typeof noteModel
>;