2016-12-28 23:49:51 +01: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 09:37:01 +01:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
2016-12-28 23:49:51 +01: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 08:55:01 +01:00
|
|
|
detail: true
|
2016-12-28 23:49:51 +01:00
|
|
|
}));
|
|
|
|
});
|