2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { getJsonSchema } from '@/core/chart/core.js';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import InstanceChart from '@/core/chart/charts/instance.js';
|
|
|
|
import { schema } from '@/core/chart/charts/entities/instance.js';
|
2019-02-08 09:58:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['charts'],
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
res: getJsonSchema(schema),
|
2022-06-25 12:26:31 +03:00
|
|
|
|
|
|
|
allowGet: true,
|
|
|
|
cacheSec: 60 * 60,
|
2022-02-19 07:05:32 +02:00
|
|
|
} as const;
|
2020-03-06 18:04:36 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
span: { type: 'string', enum: ['day', 'hour'] },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 },
|
|
|
|
offset: { type: 'integer', nullable: true, default: null },
|
|
|
|
host: { type: 'string' },
|
2019-02-23 04:20:58 +02:00
|
|
|
},
|
2022-02-19 07:05:32 +02:00
|
|
|
required: ['span', 'host'],
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2019-02-08 09:58:57 +02:00
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
private instanceChart: InstanceChart,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
return await this.instanceChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.host);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|