api - endpoint:timeline: unneed promise wrapping

This commit is contained in:
otofune 2017-11-06 15:55:47 +09:00
parent 7553c6dd38
commit 7b1fc2c5d6
1 changed files with 8 additions and 7 deletions

View File

@ -16,22 +16,22 @@ import serialize from '../../serializers/post';
* @param {any} app
* @return {Promise<any>}
*/
module.exports = (params, user, app) => new Promise(async (res, rej) => {
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param');
if (limitErr) throw 'invalid limit param';
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
if (sinceIdErr) throw 'invalid since_id param';
// Get 'max_id' parameter
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param');
if (maxIdErr) throw 'invalid max_id param';
// Check if both of since_id and max_id is specified
if (sinceId && maxId) {
return rej('cannot set since_id and max_id');
throw 'cannot set since_id and max_id';
}
const { followingIds, watchChannelIds } = await rap({
@ -92,5 +92,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
});
// Serialize
res(await Promise.all(timeline.map(post => serialize(post, user))));
});
const _timeline = await Promise.all(timeline.map(post => serialize(post, user)))
return _timeline
};