Files
dragonroll/backend/src/models/Item.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

52 lines
1.9 KiB
JavaScript

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ItemSchema = new Schema({
name: { type: String, required: true, trim: true },
category: {
type: String,
enum: ['weapon', 'armor', 'shield', 'adventuring-gear', 'magic-item', 'consumable', 'tool', 'treasure', 'other'],
default: 'adventuring-gear'
},
rarity: {
type: String,
enum: ['common', 'uncommon', 'rare', 'very-rare', 'legendary', 'artifact'],
default: 'common'
},
quantity: { type: Number, min: 1, default: 1 },
weight: { type: Number, min: 0 },
properties: { type: String, default: '' },
description: { type: String, default: '' },
// Item icon: an uploaded filename served from /api/public, or a full URL
// (Foundry sends its own icon as one).
image: { type: String, default: '' },
// The icon Foundry last sent for this item, kept even after the user picks
// their own so Dragonroll can still offer Foundry's back.
foundryImage: { type: String, default: '' },
campaign: {
type: Schema.Types.ObjectId,
ref: 'Campaign',
required: true
},
// The folder this item stands in: a Folder of the same campaign whose target is
// 'item' (null = the root of the item list).
folder: {
type: Schema.Types.ObjectId,
ref: 'Folder',
default: null
},
foundryItemId: { type: String },
// Names Foundry uses for this item. Dragonroll may rename it, and the copies
// Foundry keeps sending still have to fold into this row instead of
// creating a second item under their original name.
foundryNames: { type: [String], default: [] },
date: { type: Date, default: Date.now }
});
ItemSchema.index(
{ campaign: 1, foundryItemId: 1 },
{ unique: true, partialFilterExpression: { foundryItemId: { $type: 'string' } } }
);
module.exports = mongoose.model('Item', ItemSchema);