2016-12-28 22:49:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
import * as mongo from 'mongodb';
|
|
|
|
import DriveFolder from '../../../models/drive-folder';
|
|
|
|
import serialize from '../../../serializers/drive-folder';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a folder
|
|
|
|
*
|
2017-03-01 08:37:01 +00:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
2016-12-28 22:49:51 +00:00
|
|
|
*/
|
|
|
|
module.exports = (params, user) =>
|
|
|
|
new Promise(async (res, rej) =>
|
|
|
|
{
|
|
|
|
// Get 'folder_id' parameter
|
|
|
|
const folderId = params.folder_id;
|
|
|
|
if (folderId === undefined || folderId === null) {
|
|
|
|
return rej('folder_id is required');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get folder
|
|
|
|
const folder = await DriveFolder
|
|
|
|
.findOne({
|
|
|
|
_id: new mongo.ObjectID(folderId),
|
|
|
|
user_id: user._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (folder === null) {
|
|
|
|
return rej('folder-not-found');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize
|
|
|
|
res(await serialize(folder, {
|
2017-02-16 07:55:01 +00:00
|
|
|
detail: true
|
2016-12-28 22:49:51 +00:00
|
|
|
}));
|
|
|
|
});
|