From 7f3ff239ddddc03436a54e81c5be646ae22fe428 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 8 Jun 2017 02:46:51 +0900 Subject: [PATCH] [API] Improve aggregation/users/activity --- src/api/endpoints/aggregation/users/activity.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/endpoints/aggregation/users/activity.ts b/src/api/endpoints/aggregation/users/activity.ts index 5d2ce995f..5a3e78c44 100644 --- a/src/api/endpoints/aggregation/users/activity.ts +++ b/src/api/endpoints/aggregation/users/activity.ts @@ -14,6 +14,10 @@ import Post from '../../../models/post'; * @return {Promise} */ module.exports = (params) => new Promise(async (res, rej) => { + // Get 'limit' parameter + const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$; + if (limitErr) return rej('invalid limit param'); + // Get 'user_id' parameter const [userId, userIdErr] = $(params.user_id).id().$; if (userIdErr) return rej('invalid user_id param'); @@ -85,7 +89,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; - for (let i = 0; i < 365; i++) { + for (let i = 0; i < limit; i++) { const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d =>