Foundry and discord bot
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s

This commit is contained in:
2026-10-11 22:26:29 +02:00
parent a2b512699a
commit 1402045001
65 changed files with 5962 additions and 144 deletions

View File

@@ -0,0 +1,60 @@
const express = require('express');
const router = express.Router();
const Campaign = require('../models/Campaign');
const Item = require('../models/Item');
async function userOwnsCampaign(campaignId, userId) {
const campaign = await Campaign.findOne({ _id: campaignId, createdBy: userId }).lean();
return Boolean(campaign);
}
router.get('/list', async (req, res) => {
try {
const { campaign } = req.query;
if (!campaign) return res.json({ status: 'error', msg: 'errors.missing-data' });
if (!(await userOwnsCampaign(campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' });
const items = await Item.find({ campaign }).sort({ name: 1 }).lean();
res.json({ status: 'ok', items });
} catch (err) {
console.error(err);
res.json({ status: 'error', msg: 'errors.internal' });
}
});
router.post('/create', async (req, res) => {
try {
const { name, campaign, category, rarity, quantity, weight, properties, description } = req.body;
if (!name?.trim() || !campaign) return res.json({ status: 'error', msg: 'errors.missing-data' });
if (!(await userOwnsCampaign(campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' });
const item = await Item.create({
name: name.trim(), campaign, category, rarity,
quantity: quantity === '' || quantity === undefined ? 1 : Number(quantity),
weight: weight === '' || weight === undefined ? undefined : Number(weight),
properties, description
});
res.json({ status: 'ok', item });
} catch (err) {
console.error(err);
res.json({ status: 'error', msg: 'errors.internal' });
}
});
router.post('/delete', async (req, res) => {
try {
const { id } = req.body;
if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' });
const item = await Item.findById(id);
if (!item) return res.json({ status: 'error', msg: 'errors.notfound' });
if (!(await userOwnsCampaign(item.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' });
await item.deleteOne();
res.json({ status: 'ok' });
} catch (err) {
console.error(err);
res.json({ status: 'error', msg: 'errors.internal' });
}
});
module.exports = router;