0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +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 fields = [
'googleId',
'title',
'pageCount',
'description',

View File

@@ -262,7 +262,7 @@ const deleteBrew = async (req, res)=>{
const account = req.account;
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
const deleteGoogleBrew = googleId && isOwner;
const shouldDeleteGoogleBrew = googleId && isOwner;
if(brew._id) {
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' };
});
} 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
brew.googleId = undefined;
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)
.catch((err)=>{
console.error(err);