yumechi-no-kuni/src/api/endpoints/drive/folders/show.ts
2017-03-03 19:33:14 +09:00

39 lines
772 B
TypeScript

'use strict';
/**
* Module dependencies
*/
import it from '../../../it';
import DriveFolder from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder';
/**
* Show a folder
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
// Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed();
if (folderIdErr) return rej('invalid folder_id param');
// Get folder
const folder = await DriveFolder
.findOne({
_id: folderId,
user_id: user._id
});
if (folder === null) {
return rej('folder-not-found');
}
// Serialize
res(await serialize(folder, {
detail: true
}));
});