Fix bug
This commit is contained in:
parent
736d3100f6
commit
2bad6bd5ac
1 changed files with 21 additions and 23 deletions
|
@ -1,34 +1,32 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
|
||||
/**
|
||||
* Get drive information
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Calculate drive usage
|
||||
const usage = ((await DriveFile
|
||||
.aggregate([
|
||||
{ $match: { 'metadata.userId': user._id } },
|
||||
{
|
||||
const usage = await DriveFile
|
||||
.aggregate([{
|
||||
$match: {
|
||||
'metadata.userId': user._id,
|
||||
'metadata.deletedAt': { $exists: false }
|
||||
}
|
||||
}, {
|
||||
$project: {
|
||||
length: true
|
||||
}
|
||||
},
|
||||
{
|
||||
}, {
|
||||
$group: {
|
||||
_id: null,
|
||||
usage: { $sum: '$length' }
|
||||
}
|
||||
}])
|
||||
.then((aggregates: any[]) => {
|
||||
if (aggregates.length > 0) {
|
||||
return aggregates[0].usage;
|
||||
}
|
||||
]))[0] || {
|
||||
usage: 0
|
||||
}).usage;
|
||||
return 0;
|
||||
});
|
||||
|
||||
res({
|
||||
capacity: user.driveCapacity,
|
||||
|
|
Loading…
Reference in a new issue