const mongoose = require('mongoose'); const Schema = mongoose.Schema; const FolderSchema = new Schema({ name: { type: String, required: true }, campaign: { type: Schema.Types.ObjectId, ref: 'Campaign', required: true }, parentFolder: { type: Schema.Types.ObjectId, ref: 'Folder' }, // Which campaign list a folder belongs to. Note folders are what this model has // always held, and their rows carry no target at all, so everything reading the // note tree asks for `{ target: { $ne: 'item' } }` and keeps finding them. target: { type: String, enum: ['note', 'item'], default: 'note' }, // The Foundry item folder this row mirrors, set by the item sync only // (see routes/foundry-link.js). foundryFolderId: { type: String }, color: { type: String }, date: { type: Date, default: Date.now } }); FolderSchema.index( { campaign: 1, foundryFolderId: 1 }, { unique: true, partialFilterExpression: { foundryFolderId: { $type: 'string' } } } ); module.exports = mongoose.model('Folder', FolderSchema);