0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-02 12:52:38 +00:00

Merge branch 'master' into api-tests

This commit is contained in:
Charlie Humphreys
2023-01-03 13:47:09 -06:00
5 changed files with 270 additions and 210 deletions

View File

@@ -195,9 +195,10 @@ If you believe you should have access to this brew, ask the file owner to invite
updateBrew : async (req, res)=>{
// Initialize brew from request and body, destructure query params, set a constant for the google id, and set the initial value for the after-save method
const brewFromClient = api.excludePropsFromUpdate(req.body);
if(req.brew.version > brewFromClient.version) {
res.setHeader('Content-Type', 'application/json');
return res.status(409).send(JSON.stringify({ message: `The brew has been changed on a different device. Please save your changes elsewhere, refresh, and try again.` }));
if(req.brew.version && brewFromClient.version && req.brew.version > brewFromClient.version) {
console.log(`Version mismatch on brew ${req.body.editId}`);
// res.setHeader('Content-Type', 'application/json');
// return res.status(409).send(JSON.stringify({ message: `The brew has been changed on a different device. Please save your changes elsewhere, refresh, and try again.` }));
}
let brew = _.assign(req.brew, brewFromClient);
@@ -246,7 +247,7 @@ If you believe you should have access to this brew, ask the file owner to invite
brew.text = undefined;
}
brew.updatedAt = new Date();
brew.version += 1;
brew.version = (brew.version || 1) + 1;
if(req.account) {
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));