mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 08:03:09 +02:00
34 lines
852 B
TypeScript
34 lines
852 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import $ from 'cafy';
|
|
import DriveFolder from '../../../models/drive-folder';
|
|
import serialize from '../../../serializers/drive-folder';
|
|
|
|
/**
|
|
* Find a folder(s)
|
|
*
|
|
* @param {any} params
|
|
* @param {any} user
|
|
* @return {Promise<any>}
|
|
*/
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
// Get 'name' parameter
|
|
const [name, nameErr] = $(params.name).string().$;
|
|
if (nameErr) return rej('invalid name param');
|
|
|
|
// Get 'parent_id' parameter
|
|
const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
|
if (parentIdErr) return rej('invalid parent_id param');
|
|
|
|
// Issue query
|
|
const folders = await DriveFolder
|
|
.find({
|
|
name: name,
|
|
user_id: user._id,
|
|
parent_id: parentId
|
|
});
|
|
|
|
// Serialize
|
|
res(await Promise.all(folders.map(folder => serialize(folder))));
|
|
});
|