From 100b1e762e02d539090960d53980ce740235ef05 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 30 Aug 2018 03:49:52 +0900 Subject: [PATCH] Improve API --- src/server/api/endpoints/chart.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/server/api/endpoints/chart.ts b/src/server/api/endpoints/chart.ts index 406ad3994..521fc42c9 100644 --- a/src/server/api/endpoints/chart.ts +++ b/src/server/api/endpoints/chart.ts @@ -1,4 +1,6 @@ +import $ from 'cafy'; import Stats, { IStats } from '../../../models/stats'; +import getParams from '../../get-params'; type Omit = Pick>; @@ -44,11 +46,26 @@ function migrateStats(stats: IStats[]) { } export const meta = { + desc: { + 'ja-JP': 'インスタンスの統計を取得します。' + }, + + params: { + limit: $.num.optional.range(1, 100).note({ + default: 30, + desc: { + 'ja-JP': '最大数' + } + }), + } }; export default (params: any) => new Promise(async (res, rej) => { - const daysRange = 30; - const hoursRange = 30; + const [ps, psErr] = getParams(meta, params); + if (psErr) throw psErr; + + const daysRange = ps.limit; + const hoursRange = ps.limit; const now = new Date(); const y = now.getFullYear();