diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 06:48:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 06:48:26 +0900 |
| commit | 6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a (patch) | |
| tree | d9319e37433f57c70cdf9e66b57b525fd7bfc881 /src/api/endpoints/posts/reposts.ts | |
| parent | wip (diff) | |
| download | misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.gz misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.bz2 misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.zip | |
wip
Diffstat (limited to '')
| -rw-r--r-- | src/api/endpoints/posts/reposts.ts (renamed from src/api/endpoints/posts/reposts.js) | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/api/endpoints/posts/reposts.js b/src/api/endpoints/posts/reposts.ts index 0ffe44cb16..d8410b322b 100644 --- a/src/api/endpoints/posts/reposts.js +++ b/src/api/endpoints/posts/reposts.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../it'; import Post from '../../models/post'; import serialize from '../../serializers/post'; @@ -18,39 +18,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'post_id' parameter - const postId = params.post_id; - if (postId === undefined || postId === null) { - return rej('post_id is required'); - } + const [postId, postIdErr] = it(params.post_id, 'id', true); + if (postIdErr) return rej('invalid post_id param'); // 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'); } // Lookup post const post = await Post.findOne({ - _id: new mongo.ObjectID(postId) + _id: postId }); if (post === null) { - return rej('post not found', 'POST_NOT_FOUND'); + return rej('post not found'); } // Construct query @@ -59,15 +53,15 @@ module.exports = (params, user) => }; const query = { repost_id: post._id - }; - 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 }; } |