mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 12:12:42 +00:00
Change to aggregate query, rename variables
This commit is contained in:
@@ -50,14 +50,14 @@ const AccountPage = createClass({
|
|||||||
</div>
|
</div>
|
||||||
<div className='dataGroup'>
|
<div className='dataGroup'>
|
||||||
<h3>Homebrewery Information <NaturalCritIcon /></h3>
|
<h3>Homebrewery Information <NaturalCritIcon /></h3>
|
||||||
<p><strong>Brews on Homebrewery: </strong> {this.props.uiItems.mongoCount || '-'}</p>
|
<p><strong>Brews on Homebrewery: </strong> {this.props.uiItems.mongoCount}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className='dataGroup'>
|
<div className='dataGroup'>
|
||||||
<h3>Google Information <i className='fab fa-google-drive'></i></h3>
|
<h3>Google Information <i className='fab fa-google-drive'></i></h3>
|
||||||
<p><strong>Linked to Google: </strong> {this.props.uiItems.googleId ? 'YES' : 'NO'}</p>
|
<p><strong>Linked to Google: </strong> {this.props.uiItems.googleId ? 'YES' : 'NO'}</p>
|
||||||
{this.props.uiItems.googleId &&
|
{this.props.uiItems.googleId &&
|
||||||
<p>
|
<p>
|
||||||
<strong>Brews on Google Drive: </strong> {this.props.uiItems.fileCount != '-' ? this.props.uiItems.fileCount : <>Unable to retrieve files - <a href='https://github.com/naturalcrit/homebrewery/discussions/1580'>follow these steps to renew your Google credentials.</a></>}
|
<strong>Brews on Google Drive: </strong> {this.props.uiItems.googleCount ? this.props.uiItems.googleCount : <>Unable to retrieve files - <a href='https://github.com/naturalcrit/homebrewery/discussions/1580'>follow these steps to renew your Google credentials.</a></>}
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -280,7 +280,6 @@ app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{
|
|||||||
title : req.brew.title || 'Untitled Brew',
|
title : req.brew.title || 'Untitled Brew',
|
||||||
description : req.brew.description || 'No description.',
|
description : req.brew.description || 'No description.',
|
||||||
image : req.brew.thumbnail || defaultMetaTags.image,
|
image : req.brew.thumbnail || defaultMetaTags.image,
|
||||||
|
|
||||||
type : 'article'
|
type : 'article'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -341,7 +340,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
data.title = 'Account Information Page';
|
data.title = 'Account Information Page';
|
||||||
|
|
||||||
let auth;
|
let auth;
|
||||||
let files;
|
let googleCount = [];
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
if(req.account.googleId) {
|
if(req.account.googleId) {
|
||||||
try {
|
try {
|
||||||
@@ -353,28 +352,39 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
if(auth.credentials.access_token) {
|
if(auth.credentials.access_token) {
|
||||||
try {
|
try {
|
||||||
files = await GoogleActions.listGoogleBrews(auth);
|
googleCount = await GoogleActions.listGoogleBrews(auth);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
files = undefined;
|
googleCount = undefined;
|
||||||
console.log('List Google files failed!');
|
console.log('List Google files failed!');
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = { authors: req.account.username, googleId: { $exists: false } };
|
const aggregateQuery =[{
|
||||||
const brews = await HomebrewModel.find(query, 'id')
|
'$match' : {
|
||||||
|
'googleId' : {
|
||||||
|
'$exists' : false
|
||||||
|
},
|
||||||
|
'authors' : req.account.username
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
'$count' : 'total'
|
||||||
|
}];
|
||||||
|
const mongoCount = [];
|
||||||
|
mongoCount.push(...await HomebrewModel.aggregate(aggregateQuery)
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
}));
|
||||||
|
mongoCount.push({ total: 0 });
|
||||||
|
|
||||||
data.uiItems = {
|
data.uiItems = {
|
||||||
username : req.account.username,
|
username : req.account.username,
|
||||||
issued : req.account.issued,
|
issued : req.account.issued,
|
||||||
mongoCount : brews.length,
|
mongoCount : mongoCount[0]?.total.toString(),
|
||||||
googleId : Boolean(req.account.googleId),
|
googleId : Boolean(req.account.googleId),
|
||||||
authCheck : Boolean(req.account.googleId && auth.credentials.access_token),
|
authCheck : Boolean(req.account.googleId && auth.credentials.access_token),
|
||||||
fileCount : files?.length || '-'
|
googleCount : googleCount?.length.toString() || null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user