0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

add check for truthy version, and make sure the version exists when incrementing it

This commit is contained in:
Charlie Humphreys
2022-12-23 14:31:58 -06:00
parent 4e7a96b67c
commit ca03a473ec

View File

@@ -193,7 +193,7 @@ const newBrew = async (req, res)=>{
const 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 = excludePropsFromUpdate(req.body);
if(req.brew.version > brewFromClient.version) {
if(req.brew.version && brewFromClient.version && 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.` }));
}
@@ -244,7 +244,7 @@ const updateBrew = async (req, res)=>{
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));