From f3d5c07ada08a089969176cdb7b7bfc3f0132fda Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 2 Mar 2017 17:08:09 +0900 Subject: [PATCH] wip --- src/api/endpoints/posts/{context.js => context.ts} | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) rename src/api/endpoints/posts/{context.js => context.ts} (81%) diff --git a/src/api/endpoints/posts/context.js b/src/api/endpoints/posts/context.ts similarity index 81% rename from src/api/endpoints/posts/context.js rename to src/api/endpoints/posts/context.ts index b84304464..673da0fab 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');