summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/replies.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 06:48:26 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 06:48:26 +0900
commit6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a (patch)
treed9319e37433f57c70cdf9e66b57b525fd7bfc881 /src/api/endpoints/posts/replies.ts
parentwip (diff)
downloadmisskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.gz
misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.bz2
misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.zip
wip
Diffstat (limited to '')
-rw-r--r--src/api/endpoints/posts/replies.ts (renamed from src/api/endpoints/posts/replies.js)36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/api/endpoints/posts/replies.js b/src/api/endpoints/posts/replies.ts
index cbbb5dc312..3f448d1632 100644
--- a/src/api/endpoints/posts/replies.js
+++ b/src/api/endpoints/posts/replies.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,42 +18,28 @@ 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);
-
- // From 1 to 100
- if (!(1 <= limit && limit <= 100)) {
- return rej('invalid limit range');
- }
- } else {
- limit = 10;
- }
+ const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
+ if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
- let offset = params.offset;
- if (offset !== undefined && offset !== null) {
- offset = parseInt(offset, 10);
- } else {
- offset = 0;
- }
+ const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
+ if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
- let sort = params.sort || 'desc';
+ const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
+ if (sortError) return rej('invalid sort param');
// 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');
}
// Issue query