From 7bd6e7b7ab998391b8535389528a3603e957bc68 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 21 Oct 2026 20:24:33 +0000 Subject: [PATCH] Group brew-normalizing steps together --- server/homebrew.api.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 5715378ae..53f3c6e11 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -397,23 +397,26 @@ const api = { brew.title = brew.title.trim(); brew.description = brew.description.trim() || ''; brew.text = api.mergeBrewText(brew); + brew.updatedAt = new Date(); + brew.version = (brew.version || 1) + 1; + if(req.account) { + brew.authors = _.uniq(_.concat(brew.authors, req.account.username)); + brew.invitedAuthors = _.uniq(_.filter(brew.invitedAuthors, (a)=>req.account.username !== a)); + } //=====----- Update to or remove from Google Drive -----=========// const googleId = brew.googleId; const { saveToGoogle, removeFromGoogle } = req.query; - if(brew.googleId && removeFromGoogle) { - // If the google id exists and we're removing it from google, mark the brew's google id as undefined + if(brew.googleId && removeFromGoogle) { // If removing from google, remove the brew's googleId brew.googleId = undefined; - } else if(!brew.googleId && saveToGoogle) { - // If we don't have a google id and the user wants to save to google, create the google brew and set the google id on the brew + } + else if(!brew.googleId && saveToGoogle) { // If adding to google, create new google document and record the googleId brew.googleId = await api.newGoogleBrew(req.account, brew, res); - if(!brew.googleId) return; - } else if(brew.googleId) { - // If the google id exists and no other actions are being performed, update the google brew + } + else if(brew.googleId) { // If already on google, update the google brew const updated = await GoogleActions.updateGoogleBrew(api.excludeGoogleProps(brew), req.ip); - if(!updated) return; } @@ -427,13 +430,6 @@ const api = { // Delete the non-binary text field since it's not needed anymore brew.text = undefined; } - brew.updatedAt = new Date(); - brew.version = (brew.version || 1) + 1; - - if(req.account) { - brew.authors = _.uniq(_.concat(brew.authors, req.account.username)); - brew.invitedAuthors = _.uniq(_.filter(brew.invitedAuthors, (a)=>req.account.username !== a)); - } // define a function to catch our save errors const saveError = (err)=>{