mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 16:22:42 +00:00
server side
This commit is contained in:
@@ -414,6 +414,28 @@ const api = {
|
|||||||
|
|
||||||
res.status(200).send(saved);
|
res.status(200).send(saved);
|
||||||
},
|
},
|
||||||
|
deleteAuthor : async (req, res)=>{
|
||||||
|
try {
|
||||||
|
await api.getBrew('edit')(req, res, ()=>{});
|
||||||
|
} catch (err) {
|
||||||
|
throw { name: 'deleteAuthor Error', message: err, status: 500, brewId: brew._id };
|
||||||
|
}
|
||||||
|
|
||||||
|
let brew = req.brew;
|
||||||
|
const account = req.account;
|
||||||
|
const author = req.params.author;
|
||||||
|
const isOwner = account && (brew.authors[0] === account.username);
|
||||||
|
|
||||||
|
if(brew._id && isOwner) {
|
||||||
|
brew = _.assign(await HomebrewModel.findOne({ _id: brew._id }), brew);
|
||||||
|
brew.authors = _.pull(brew.authors, author);
|
||||||
|
brew.markModified('authors'); //Mongo will not properly update arrays without markModified()
|
||||||
|
await brew.save().catch((err)=>{
|
||||||
|
throw { name: 'deleteAuthor Error', message: err, status: 500, HBErrorCode: '08', brewId: brew._id };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(204).send();
|
||||||
|
},
|
||||||
deleteGoogleBrew : async (account, id, editId, res)=>{
|
deleteGoogleBrew : async (account, id, editId, res)=>{
|
||||||
const auth = await GoogleActions.authCheck(account, res);
|
const auth = await GoogleActions.authCheck(account, res);
|
||||||
await GoogleActions.deleteGoogleBrew(auth, id, editId);
|
await GoogleActions.deleteGoogleBrew(auth, id, editId);
|
||||||
@@ -485,6 +507,7 @@ router.post('/api', checkClientVersion, asyncHandler(api.newBrew));
|
|||||||
router.put('/api/:id', checkClientVersion, asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
router.put('/api/:id', checkClientVersion, asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
||||||
router.put('/api/update/:id', checkClientVersion, asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
router.put('/api/update/:id', checkClientVersion, asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
||||||
router.delete('/api/:id', checkClientVersion, asyncHandler(api.deleteBrew));
|
router.delete('/api/:id', checkClientVersion, asyncHandler(api.deleteBrew));
|
||||||
|
router.put('/api/:id/:author', checkClientVersion, asyncHandler(api.deleteAuthor));
|
||||||
router.get('/api/remove/:id', checkClientVersion, asyncHandler(api.deleteBrew));
|
router.get('/api/remove/:id', checkClientVersion, asyncHandler(api.deleteBrew));
|
||||||
router.get('/api/theme/:renderer/:id', asyncHandler(api.getThemeBundle));
|
router.get('/api/theme/:renderer/:id', asyncHandler(api.getThemeBundle));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user