From 3046d3e7c02df67862564202cf661aa1bb60e942 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Mar 2017 00:02:40 +0900 Subject: [PATCH] [API] #158 --- src/api/serializers/drive-folder.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/serializers/drive-folder.ts b/src/api/serializers/drive-folder.ts index 34fdc0d905..a428464108 100644 --- a/src/api/serializers/drive-folder.ts +++ b/src/api/serializers/drive-folder.ts @@ -3,6 +3,7 @@ */ import * as mongo from 'mongodb'; import DriveFolder from '../models/drive-folder'; +import DriveFile from '../models/drive-file'; import deepcopy = require('deepcopy'); /** @@ -37,6 +38,19 @@ const self = ( _folder.id = _folder._id; delete _folder._id; + if (opts.detail) { + const childFoldersCount = await DriveFolder.count({ + parent_id: _folder.id + }); + + const childFilesCount = await DriveFile.count({ + folder_id: _folder.id + }); + + _folder.folders_count = childFoldersCount; + _folder.files_count = childFilesCount; + } + if (opts.detail && _folder.parent_id) { // Populate parent folder _folder.parent = await self(_folder.parent_id, {