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