0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Merge pull request #2618 from naturalcrit/FixGoogleBrewsDuplicatingOnStub

Fix Google Drive brews duplicating
This commit is contained in:
Trevor Buckner
2023-01-20 17:25:47 -05:00
committed by GitHub
3 changed files with 13 additions and 9 deletions

View File

@@ -59,6 +59,12 @@ For a full record of development, visit our [Github Page](https://github.com/nat
### v3.6.0
{{taskList
##### calculuschild
* [x] Fix Google Drive brews sometimes duplicating
Fixes issues [#2603](https://github.com/naturalcrit/homebrewery/issues/2603)
##### Jeddai
* [x] Add unit tests with full coverage for the Homebrewery API

View File

@@ -109,7 +109,7 @@ If you believe you should have access to this brew, ask the file owner to invite
excludePropsFromUpdate : (brew)=>{
// Remove undesired properties
const modified = _.clone(brew);
const propsToExclude = ['_id', 'views', 'lastViewed', 'editId', 'shareId', 'googleId'];
const propsToExclude = ['_id', 'views', 'lastViewed'];
for (const prop of propsToExclude) {
delete modified[prop];
}
@@ -189,17 +189,18 @@ If you believe you should have access to this brew, ask the file owner to invite
res.status(200).send(saved);
},
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, and set the initial value for the after-save method
const brewFromClient = api.excludePropsFromUpdate(req.body);
if(req.brew.version && brewFromClient.version && req.brew.version > brewFromClient.version) {
console.log(`Version mismatch on brew ${req.body.editId}`);
const brewFromServer = req.brew;
if(brewFromServer.version && brewFromClient.version && brewFromServer.version > brewFromClient.version) {
console.log(`Version mismatch on brew ${brewFromClient.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);
const { saveToGoogle, removeFromGoogle } = req.query;
let brew = _.assign(brewFromServer, brewFromClient);
const googleId = brew.googleId;
const { saveToGoogle, removeFromGoogle } = req.query;
let afterSave = async ()=>true;
brew.text = api.mergeBrewText(brew);

View File

@@ -342,9 +342,6 @@ brew`);
expect(result._id).toBeUndefined();
expect(result.views).toBeUndefined();
expect(result.lastViewed).toBeUndefined();
expect(result.editId).toBeUndefined();
expect(result.shareId).toBeUndefined();
expect(result.googleId).toBeUndefined();
});
it('excludeGoogleProps removes the correct keys', ()=>{