Files
dragonroll/backend/src/models/Folder.js
Gitea OpenCode Agent 1f9ab330b9
Some checks failed
Test / test (push) Failing after 2s
Fix issue #44: Sync item folders
2026-10-14 23:39:26 +00:00

32 lines
1.1 KiB
JavaScript

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);