sharkey/src/server/api/endpoints/drive/folders/find.ts
syuilo 2756f553c6
Improve error handling of API (#4345)
* wip

* wip

* wip

* Update attached_notes.ts

* wip

* Refactor

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update call.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* ✌️

* Fix
2019-02-22 11:46:58 +09:00

37 lines
712 B
TypeScript

import $ from 'cafy';
import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { pack } from '../../../../../models/drive-folder';
import define from '../../../define';
export const meta = {
requireCredential: true,
kind: 'drive-read',
params: {
name: {
validator: $.str
},
parentId: {
validator: $.optional.nullable.type(ID),
transform: transform,
default: null as any,
desc: {
'ja-JP': 'フォルダID'
}
},
}
};
export default define(meta, async (ps, user) => {
const folders = await DriveFolder
.find({
name: ps.name,
userId: user._id,
parentId: ps.parentId
});
return await Promise.all(folders.map(folder => pack(folder)));
});