summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/timeline.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/api/endpoints/posts/timeline.ts (renamed from src/api/endpoints/posts/timeline.js)34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/api/endpoints/posts/timeline.js b/src/api/endpoints/posts/timeline.ts
index 48f7c26940..5744084932 100644
--- a/src/api/endpoints/posts/timeline.js
+++ b/src/api/endpoints/posts/timeline.ts
@@ -3,7 +3,7 @@
/**
* Module dependencies
*/
-import * as mongo from 'mongodb';
+import it from '../../it';
import Post from '../../models/post';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
@@ -20,23 +20,19 @@ module.exports = (params, user, app) =>
new Promise(async (res, rej) =>
{
// Get 'limit' parameter
- let limit = params.limit;
- if (limit !== undefined && limit !== null) {
- limit = parseInt(limit, 10);
+ const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
+ if (limitErr) return rej('invalid limit param');
- // From 1 to 100
- if (!(1 <= limit && limit <= 100)) {
- return rej('invalid limit range');
- }
- } else {
- limit = 10;
- }
+ // Get 'since_id' parameter
+ const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
+ if (sinceIdErr) return rej('invalid since_id param');
- const since = params.since_id || null;
- const max = params.max_id || null;
+ // Get 'max_id' parameter
+ const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
+ if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified
- if (since !== null && max !== null) {
+ if (sinceId !== null && maxId !== null) {
return rej('cannot set since_id and max_id');
}
@@ -51,15 +47,15 @@ module.exports = (params, user, app) =>
user_id: {
$in: followingIds
}
- };
- if (since !== null) {
+ } as any;
+ if (sinceId) {
sort._id = 1;
query._id = {
- $gt: new mongo.ObjectID(since)
+ $gt: sinceId
};
- } else if (max !== null) {
+ } else if (maxId) {
query._id = {
- $lt: new mongo.ObjectID(max)
+ $lt: maxId
};
}