Sharkey/src/server/api/endpoints/charts/notes.ts

34 lines
848 B
TypeScript
Raw Normal View History

2018-10-21 03:20:11 +03:00
import $ from 'cafy';
import getParams from '../../get-params';
2018-10-22 23:36:35 +03:00
import notesChart from '../../../../chart/notes';
2018-10-21 03:20:11 +03:00
export const meta = {
desc: {
2018-10-22 23:36:35 +03:00
'ja-JP': '投稿のチャートを取得します。'
2018-10-21 03:20:11 +03:00
},
params: {
span: $.str.or(['day', 'hour']).note({
desc: {
2018-10-22 11:06:53 +03:00
'ja-JP': '集計のスパン (day または hour)'
2018-10-21 03:20:11 +03:00
}
}),
limit: $.num.optional.range(1, 100).note({
default: 30,
desc: {
'ja-JP': '最大数。例えば 30 を指定したとすると、スパンが"day"の場合は30日分のデータが、スパンが"hour"の場合は30時間分のデータが返ります。'
}
}),
}
};
export default (params: any) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
2018-10-22 23:36:35 +03:00
const stats = await notesChart.getChart(ps.span as any, ps.limit);
2018-10-21 03:20:11 +03:00
res(stats);
});