summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 02:42:17 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 02:42:17 +0900
commitd5e5419dfc14bbb8a1329c2028134b0999883258 (patch)
tree22345847c41dee9f57d28538f4a8c9fe862be18f /src/api/endpoints
parentFix bug (diff)
downloadsharkey-d5e5419dfc14bbb8a1329c2028134b0999883258.tar.gz
sharkey-d5e5419dfc14bbb8a1329c2028134b0999883258.tar.bz2
sharkey-d5e5419dfc14bbb8a1329c2028134b0999883258.zip
wip
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/posts/context.ts27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts
index 673da0fab8..25ac687d34 100644
--- a/src/api/endpoints/posts/context.ts
+++ b/src/api/endpoints/posts/context.ts
@@ -3,7 +3,7 @@
/**
* Module dependencies
*/
-import validate from '../../validator';
+import it from '../../it';
import Post from '../../models/post';
import serialize from '../../serializers/post';
@@ -18,37 +18,24 @@ module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter
- const [postId, postIdErr] = validate(params.post_id, 'id', true);
+ const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id');
// Get 'limit' parameter
- let [limit, limitErr] = validate(params.limit, 'number');
+ const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limitErr) return rej('invalid limit');
- if (limit !== null) {
- // From 1 to 100
- if (!(1 <= limit && limit <= 100)) {
- return rej('invalid limit range');
- }
- } else {
- limit = 10;
- }
-
// Get 'offset' parameter
- let offset = params.offset;
- if (offset !== undefined && offset !== null) {
- offset = parseInt(offset, 10);
- } else {
- offset = 0;
- }
+ const [offset, offsetErr] = it(params.limit).expect.number().min(0).default(0).qed();
+ if (offsetErr) return rej('invalid offset');
// 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');
}
const context = [];