diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-02 17:08:09 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-02 17:08:09 +0900 |
| commit | f3d5c07ada08a089969176cdb7b7bfc3f0132fda (patch) | |
| tree | f54d6b6d7702bbd3d2c4d2777c2c1c6262ec6ce3 /src/api | |
| parent | wip (diff) | |
| download | sharkey-f3d5c07ada08a089969176cdb7b7bfc3f0132fda.tar.gz sharkey-f3d5c07ada08a089969176cdb7b7bfc3f0132fda.tar.bz2 sharkey-f3d5c07ada08a089969176cdb7b7bfc3f0132fda.zip | |
wip
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/endpoints/posts/context.ts (renamed from src/api/endpoints/posts/context.js) | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/api/endpoints/posts/context.js b/src/api/endpoints/posts/context.ts index b843044642..673da0fab8 100644 --- a/src/api/endpoints/posts/context.js +++ b/src/api/endpoints/posts/context.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import validate from '../../validator'; import Post from '../../models/post'; import serialize from '../../serializers/post'; @@ -18,16 +18,14 @@ 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] = validate(params.post_id, 'id', true); + if (postIdErr) return rej('invalid post_id'); // Get 'limit' parameter - let limit = params.limit; - if (limit !== undefined && limit !== null) { - limit = parseInt(limit, 10); + let [limit, limitErr] = validate(params.limit, 'number'); + if (limitErr) return rej('invalid limit'); + if (limit !== null) { // From 1 to 100 if (!(1 <= limit && limit <= 100)) { return rej('invalid limit range'); |