From b72acd9e59a1cfd3944bd7b58e625b4723fa0854 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 10 Dec 2022 13:31:57 -0500 Subject: [PATCH] cleanup --- .../pages/accountPage/accountPage.jsx | 2 +- server/app.js | 22 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 95d77e9bb..77f246a8b 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -57,7 +57,7 @@ const AccountPage = createClass({

Linked to Google: {this.props.uiItems.googleId ? 'YES' : 'NO'}

{this.props.uiItems.googleId &&

- Brews on Google Drive: {this.props.uiItems.googleCount ? this.props.uiItems.googleCount : <>Unable to retrieve files - follow these steps to renew your Google credentials.} + Brews on Google Drive: {this.props.uiItems.googleCount ?? <>Unable to retrieve files - follow these steps to renew your Google credentials.}

} diff --git a/server/app.js b/server/app.js index 6d732429c..8a3e4c12a 100644 --- a/server/app.js +++ b/server/app.js @@ -361,30 +361,20 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ } } - const aggregateQuery =[{ - '$match' : { - 'googleId' : { - '$exists' : false - }, - 'authors' : req.account.username - } - }, { - '$count' : 'total' - }]; - const mongoCount = []; - mongoCount.push(...await HomebrewModel.aggregate(aggregateQuery) + const query = { authors: req.account.username, googleId: { $exists: false } }; + const mongoCount = await HomebrewModel.countDocuments(query) .catch((err)=>{ + mongoCount = 0; console.log(err); - })); - mongoCount.push({ total: 0 }); + }); data.uiItems = { username : req.account.username, issued : req.account.issued, - mongoCount : mongoCount[0]?.total.toString(), googleId : Boolean(req.account.googleId), authCheck : Boolean(req.account.googleId && auth.credentials.access_token), - googleCount : googleCount?.length.toString() || null + mongoCount : mongoCount, + googleCount : googleCount?.length }; }