api - endpoint:timeline: unneed promise wrapping
This commit is contained in:
parent
7553c6dd38
commit
7b1fc2c5d6
@ -16,22 +16,22 @@ import serialize from '../../serializers/post';
|
|||||||
* @param {any} app
|
* @param {any} app
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
module.exports = async (params, user, app) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
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
|
// Get 'since_id' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
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
|
// Get 'max_id' parameter
|
||||||
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
|
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
|
// Check if both of since_id and max_id is specified
|
||||||
if (sinceId && maxId) {
|
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({
|
const { followingIds, watchChannelIds } = await rap({
|
||||||
@ -92,5 +92,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await Promise.all(timeline.map(post => serialize(post, user))));
|
const _timeline = await Promise.all(timeline.map(post => serialize(post, user)))
|
||||||
});
|
return _timeline
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user