Files
dragonroll/backend/src/models/Item.js
Aran Roig af76cf1050
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m6s
Things
2026-10-13 22:50:51 +02:00

39 lines
1.3 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: '' },
campaign: {
type: Schema.Types.ObjectId,
ref: 'Campaign',
required: true
},
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);