update report h6

This commit is contained in:
thanhnv
2026-07-20 23:47:09 +07:00
parent f462079435
commit 4b6819f578
38 changed files with 1244 additions and 62 deletions
@@ -0,0 +1,37 @@
import { BadRequestException, Controller, Get, Header, Inject, Query, Res } from '@nestjs/common';
import type { Response } from 'express';
import { ok } from '../common/api-response.js';
import { parseH6ReportQuery, type H6ReportQueryParams } from './h6-report.js';
import { ReportsService } from './reports.service.js';
interface H6QueryParams extends H6ReportQueryParams {
format?: string;
}
@Controller('api/v1/reports')
export class ReportsController {
constructor(@Inject(ReportsService) private readonly reports: ReportsService) {}
@Get()
catalog() {
return ok(this.reports.catalog());
}
@Get('h6')
h6(@Query() raw: H6QueryParams) {
return ok(this.reports.h6(parseH6ReportQuery(raw)));
}
@Get('h6/export')
@Header('Cache-Control', 'no-store')
exportH6(@Query() raw: H6QueryParams, @Res() response: Response) {
const format = raw.format ?? 'json';
if (format !== 'json' && format !== 'html') throw new BadRequestException('H6_REPORT_INVALID_FORMAT');
const report = this.reports.h6(parseH6ReportQuery(raw));
const body = this.reports.serializeH6(report, format);
const stamp = report.generated_at.slice(0, 10);
response.type(format === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8');
response.setHeader('Content-Disposition', `attachment; filename="casan-h6-report-${stamp}.${format}"`);
response.send(body);
}
}