summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/charts/ap-request.ts
blob: 38bbddb27a1d955a6d9d46d155b4c85e59015ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import $ from 'cafy';
import define from '../../define';
import { convertLog } from '@/services/chart/core';
import { apRequestChart } from '@/services/chart/index';

export const meta = {
	tags: ['charts'],

	params: {
		span: {
			validator: $.str.or(['day', 'hour']),
		},

		limit: {
			validator: $.optional.num.range(1, 500),
			default: 30,
		},

		offset: {
			validator: $.optional.nullable.num,
			default: null,
		},
	},

	// TODO: response definition
} as const;

// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps) => {
	return await apRequestChart.getChart(ps.span as any, ps.limit!, ps.offset ? new Date(ps.offset) : null);
});