Fix issue #38: Implement tokens on maps
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user