This commit is contained in:
syuilo 2017-03-02 17:08:09 +09:00
parent 7f4db37ff4
commit f3d5c07ada

View file

@ -3,7 +3,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import * as mongo from 'mongodb'; import validate from '../../validator';
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -18,16 +18,14 @@ module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>
{ {
// Get 'post_id' parameter // Get 'post_id' parameter
const postId = params.post_id; const [postId, postIdErr] = validate(params.post_id, 'id', true);
if (postId === undefined || postId === null) { if (postIdErr) return rej('invalid post_id');
return rej('post_id is required');
}
// Get 'limit' parameter // Get 'limit' parameter
let limit = params.limit; let [limit, limitErr] = validate(params.limit, 'number');
if (limit !== undefined && limit !== null) { if (limitErr) return rej('invalid limit');
limit = parseInt(limit, 10);
if (limit !== null) {
// From 1 to 100 // From 1 to 100
if (!(1 <= limit && limit <= 100)) { if (!(1 <= limit && limit <= 100)) {
return rej('invalid limit range'); return rej('invalid limit range');