mizzkey/src/api/endpoints/drive/folders/show.js

42 lines
794 B
JavaScript
Raw Normal View History

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
*
* @param {Object} params
* @param {Object} user
* @return {Promise<object>}
*/
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
}));
});