This commit is contained in:
@@ -4,6 +4,7 @@ const router = express.Router();
|
||||
const Campaign = require('../models/Campaign');
|
||||
const Folder = require('../models/Folder');
|
||||
const Note = require('../models/Note');
|
||||
const Item = require('../models/Item');
|
||||
|
||||
async function userOwnsCampaign(campaignId, userId) {
|
||||
const campaign = await Campaign.findOne({ _id: campaignId, createdBy: userId }).lean();
|
||||
@@ -18,7 +19,7 @@ router.get('/list', async (req, res) => {
|
||||
const hasAccess = await userOwnsCampaign(campaign, req.user.id);
|
||||
if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' });
|
||||
|
||||
const folders = await Folder.find({ campaign })
|
||||
const folders = await Folder.find({ campaign, target: { $ne: 'item' } })
|
||||
.select('_id name date color')
|
||||
.sort({ date: -1 })
|
||||
.lean();
|
||||
@@ -89,6 +90,12 @@ router.post('/delete', async (req, res) => {
|
||||
{ folder: folderId },
|
||||
{ $set: { folder: null, date: Date.now() } }
|
||||
);
|
||||
// Item folders share this model: the items inside move to the root of
|
||||
// the item list rather than point at a folder that is gone.
|
||||
await Item.updateMany(
|
||||
{ folder: folderId },
|
||||
{ $set: { folder: null } }
|
||||
);
|
||||
await Folder.deleteOne({ _id: folderId });
|
||||
for (const sub of subfolders) {
|
||||
await moveRecursive(sub._id);
|
||||
|
||||
Reference in New Issue
Block a user