0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 03:32:40 +00:00

fix data reuse and add field to projection

This commit is contained in:
Charlie Humphreys
2022-06-06 14:59:40 +00:00
parent bade09c24c
commit 92b3f8252e
2 changed files with 4 additions and 3 deletions

View File

@@ -165,6 +165,7 @@ app.get('/user/:username', async (req, res, next)=>{
const ownAccount = req.account && (req.account.username == req.params.username); const ownAccount = req.account && (req.account.username == req.params.username);
const fields = [ const fields = [
'googleId',
'title', 'title',
'pageCount', 'pageCount',
'description', 'description',

View File

@@ -262,7 +262,7 @@ const deleteBrew = async (req, res)=>{
const account = req.account; const account = req.account;
const isOwner = account && (brew.authors.length === 0 || brew.authors[0] === account.username); const isOwner = account && (brew.authors.length === 0 || brew.authors[0] === account.username);
// If the user is the owner and the file is saved to google, mark the google brew for deletion // If the user is the owner and the file is saved to google, mark the google brew for deletion
const deleteGoogleBrew = googleId && isOwner; const shouldDeleteGoogleBrew = googleId && isOwner;
if(brew._id) { if(brew._id) {
brew = _.assign(await HomebrewModel.findOne({ _id: brew._id }), brew); brew = _.assign(await HomebrewModel.findOne({ _id: brew._id }), brew);
@@ -280,7 +280,7 @@ const deleteBrew = async (req, res)=>{
throw { status: 500, message: 'Error while removing' }; throw { status: 500, message: 'Error while removing' };
}); });
} else { } else {
if(deleteGoogleBrew) { if(shouldDeleteGoogleBrew) {
// When there are still authors remaining, we delete the google brew but store the full brew in the Homebrewery database // When there are still authors remaining, we delete the google brew but store the full brew in the Homebrewery database
brew.googleId = undefined; brew.googleId = undefined;
brew.textBin = zlib.deflateRawSync(brew.text); brew.textBin = zlib.deflateRawSync(brew.text);
@@ -294,7 +294,7 @@ const deleteBrew = async (req, res)=>{
}); });
} }
} }
if(deleteGoogleBrew) { if(shouldDeleteGoogleBrew) {
const deleted = await deleteGoogleBrew(account, googleId, editId, res) const deleted = await deleteGoogleBrew(account, googleId, editId, res)
.catch((err)=>{ .catch((err)=>{
console.error(err); console.error(err);