0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 14:22:52 +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)=>{ 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 // 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); 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'); 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.` })); 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.text = undefined;
} }
brew.updatedAt = new Date(); brew.updatedAt = new Date();
brew.version += 1; brew.version = (brew.version || 1) + 1;
if(req.account) { if(req.account) {
brew.authors = _.uniq(_.concat(brew.authors, req.account.username)); brew.authors = _.uniq(_.concat(brew.authors, req.account.username));