0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 05:12:39 +00:00

server side

This commit is contained in:
Víctor Losada Hernández
2025-05-11 23:59:30 +02:00
parent c35138e7e3
commit f040805d09

View File

@@ -414,6 +414,28 @@ const api = {
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)=>{
const auth = await GoogleActions.authCheck(account, res);
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/update/:id', checkClientVersion, asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
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/theme/:renderer/:id', asyncHandler(api.getThemeBundle));