0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-01 19:32:42 +00:00

Remove undesired properties from brews prior to updating

Clean up tab/spacing in `googleActions.js`
This commit is contained in:
G.Ambatte
2021-08-26 17:21:45 +12:00
parent 8e841c6825
commit 941bb94190
2 changed files with 27 additions and 15 deletions

View File

@@ -61,10 +61,20 @@ const newBrew = (req, res)=>{
});
};
const cleanBrew = (brew)=>{
// Remove undesired properties
const undesiredPropertyNames=['views', 'lastViewed'];
for (const undesiredProperty of undesiredPropertyNames) {
delete brew[undesiredProperty];
};
return brew;
};
const updateBrew = (req, res)=>{
HomebrewModel.get({ editId: req.params.id })
.then((brew)=>{
brew = _.merge(brew, req.body);
const updateBrew = cleanBrew(req.body);
brew = _.merge(brew, updateBrew);
brew.text = mergeBrewText(brew.text, brew.style);
// Compress brew text to binary before saving
@@ -151,7 +161,7 @@ const updateGoogleBrew = async (req, res, next)=>{
try { oAuth2Client = GoogleActions.authCheck(req.account, res); } catch (err) { return res.status(err.status).send(err.message); }
const brew = req.body;
const brew = cleanBrew(req.body);
brew.text = mergeBrewText(brew.text, brew.style);
const updatedBrew = await GoogleActions.updateGoogleBrew(oAuth2Client, brew);