Fix issue #38: Implement tokens on maps
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-14 18:41:17 +00:00
parent ef343dbdd8
commit d567b5d171
12 changed files with 826 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ const upload = require('../services/storage');
const Campaign = require('../models/Campaign');
const Actor = require('../models/Actor');
const Map = require('../models/Map');
async function userOwnsCampaign(campaignId, userId) {
const campaign = await Campaign.findOne({ _id: campaignId, createdBy: userId }).lean();
@@ -101,6 +102,11 @@ router.post('/delete', async (req, res) => {
if (!actor) return res.json({ status: 'error', msg: 'errors.notfound' });
if (!(await userOwnsCampaign(actor.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' });
await actor.deleteOne();
// A token pointing at an actor that is gone would stand on the maps for nothing: drop those
// along with the actor, like the pins of a deleted note.
await Map.updateMany({ 'tokens.actor': id }, { $pull: { tokens: { actor: id } } });
res.json({ status: 'ok' });
} catch (err) {
console.error(err);