yumechi-no-kuni/src/api/endpoints/drive/folders/show.js

42 lines
785 B
JavaScript
Raw Normal View History

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