mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 19:22:47 +00:00
Fixing delete buttons
Delete should now first remove the current user as an editor, and only delete the file if he was the last editor. Currently, anyone who views your brew is added as an editor and if they delete it, the whole brew is deleted for everyone.
This commit is contained in:
@@ -67,11 +67,26 @@ router.put('/api/update/:id', (req, res)=>{
|
|||||||
router.get('/api/remove/:id', (req, res)=>{
|
router.get('/api/remove/:id', (req, res)=>{
|
||||||
HomebrewModel.find({ editId: req.params.id }, (err, objs)=>{
|
HomebrewModel.find({ editId: req.params.id }, (err, objs)=>{
|
||||||
if(!objs.length || err) return res.status(404).send('Can not find homebrew with that id');
|
if(!objs.length || err) return res.status(404).send('Can not find homebrew with that id');
|
||||||
const resEntry = objs[0];
|
const brew = objs[0];
|
||||||
resEntry.remove((err)=>{
|
|
||||||
if(err) return res.status(500).send('Error while removing');
|
// Remove current user as author
|
||||||
return res.status(200).send();
|
if(req.account){
|
||||||
});
|
brew.authors = _.pull(brew.authors, req.account.username);
|
||||||
|
brew.markModified('authors');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete brew if there are no authors left
|
||||||
|
if(!brew.authors.length)
|
||||||
|
brew.remove((err)=>{
|
||||||
|
if(err) return res.status(500).send('Error while removing');
|
||||||
|
return res.status(200).send();
|
||||||
|
});
|
||||||
|
// Otherwise, save the brew with updated author list
|
||||||
|
else
|
||||||
|
brew.save((err, savedBrew)=>{
|
||||||
|
if(err) throw err;
|
||||||
|
return res.status(200).send(savedBrew);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,4 +142,4 @@ module.exports = function(app){
|
|||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user