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:
@@ -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',
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user