import mongoose from 'mongoose'; import { generateId } from '../../utils.js'; const { Schema } = mongoose; const noteSchema = new mongoose.Schema({ _reference: { type: String, default: () => generateId()() }, parent: { type: Schema.Types.ObjectId, refPath: 'parentType', required: true, }, parentType: { type: String, required: true, }, content: { type: String, required: true, }, noteType: { type: Schema.Types.ObjectId, ref: 'noteType', required: true, }, createdAt: { type: Date, required: true, default: Date.now, }, updatedAt: { type: Date, required: true, default: Date.now, }, user: { type: Schema.Types.ObjectId, ref: 'user', required: false, }, }); noteSchema.virtual('id').get(function () { return this._id; }); noteSchema.set('toJSON', { virtuals: true }); export const noteModel = mongoose.model('note', noteSchema);