From 89e6bada56cb74ca3b910660e6646126e2e355d9 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 29 Nov 2022 10:26:44 +1300 Subject: [PATCH 1/3] Add link to instructions to refresh Google creds --- client/homebrew/pages/accountPage/accountPage.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 644ab13d8..0b7369949 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -42,7 +42,6 @@ const AccountPage = createClass({ }, renderUiItems : function() { - // console.log(this.props.uiItems); return <>

Account Information

@@ -56,7 +55,11 @@ const AccountPage = createClass({

Google Information

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

- {this.props.uiItems.googleId ?

Brews on Google Drive: {this.props.uiItems.fileCount || '-'}

: '' } + {this.props.uiItems.googleId && +

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

+ }
; }, From d0a1ef9571ac7eeee4716f310f19d4205840adcb Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 9 Dec 2022 18:35:17 +1300 Subject: [PATCH 2/3] Change to aggregate query, rename variables --- .../pages/accountPage/accountPage.jsx | 4 +-- server/app.js | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 0b7369949..95d77e9bb 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -50,14 +50,14 @@ const AccountPage = createClass({

Homebrewery Information

-

Brews on Homebrewery: {this.props.uiItems.mongoCount || '-'}

+

Brews on Homebrewery: {this.props.uiItems.mongoCount}

Google Information

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

{this.props.uiItems.googleId &&

- Brews on Google Drive: {this.props.uiItems.fileCount != '-' ? this.props.uiItems.fileCount : <>Unable to retrieve files - follow these steps to renew your Google credentials.} + Brews on Google Drive: {this.props.uiItems.googleCount ? 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 4afd0e8c7..6d732429c 100644 --- a/server/app.js +++ b/server/app.js @@ -280,7 +280,6 @@ app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{ title : req.brew.title || 'Untitled Brew', description : req.brew.description || 'No description.', image : req.brew.thumbnail || defaultMetaTags.image, - type : 'article' }; @@ -341,7 +340,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ data.title = 'Account Information Page'; let auth; - let files; + let googleCount = []; if(req.account) { if(req.account.googleId) { try { @@ -353,28 +352,39 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ } if(auth.credentials.access_token) { try { - files = await GoogleActions.listGoogleBrews(auth); + googleCount = await GoogleActions.listGoogleBrews(auth); } catch (e) { - files = undefined; + googleCount = undefined; console.log('List Google files failed!'); console.log(e); } } } - const query = { authors: req.account.username, googleId: { $exists: false } }; - const brews = await HomebrewModel.find(query, 'id') + const aggregateQuery =[{ + '$match' : { + 'googleId' : { + '$exists' : false + }, + 'authors' : req.account.username + } + }, { + '$count' : 'total' + }]; + const mongoCount = []; + mongoCount.push(...await HomebrewModel.aggregate(aggregateQuery) .catch((err)=>{ console.log(err); - }); + })); + mongoCount.push({ total: 0 }); data.uiItems = { - username : req.account.username, - issued : req.account.issued, - mongoCount : brews.length, - googleId : Boolean(req.account.googleId), - authCheck : Boolean(req.account.googleId && auth.credentials.access_token), - fileCount : files?.length || '-' + 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 }; } From b72acd9e59a1cfd3944bd7b58e625b4723fa0854 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 10 Dec 2022 13:31:57 -0500 Subject: [PATCH 3/3] 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 }; }