fase(15): reporting module with pdf generation

This commit is contained in:
debian
2026-03-06 05:57:05 -05:00
parent 3ff36f0b6a
commit cffa1aeea9
64 changed files with 3462 additions and 87 deletions

View File

@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KyselyReportRepository = void 0;
const Report_1 = require("../../domain/entities/Report");
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
const ReportFormat_1 = require("../../domain/value-objects/ReportFormat");
const ReportStatus_1 = require("../../domain/value-objects/ReportStatus");
class KyselyReportRepository {
constructor(db) {
this.db = db;
}
async save(report) {
const row = {
id: report.id.toString(),
title: report.title,
format: report.format.value,
status: report.status.value,
filters_json: JSON.stringify(report.filters),
file_path: report.filePath ?? null,
error_message: report.errorMessage ?? null,
total_findings: report.totalFindings,
created_at: report.createdAt.getTime(),
completed_at: report.completedAt ? report.completedAt.getTime() : null,
};
await this.db.insertInto('reports').values(row).execute();
}
async findById(id) {
const row = await this.db
.selectFrom('reports')
.selectAll()
.where('id', '=', id)
.executeTakeFirst();
return row ? this.toDomain(row) : undefined;
}
async findAll() {
const rows = await this.db
.selectFrom('reports')
.selectAll()
.orderBy('created_at', 'desc')
.execute();
return rows.map(r => this.toDomain(r));
}
async update(report) {
await this.db
.updateTable('reports')
.set({
status: report.status.value,
file_path: report.filePath ?? null,
error_message: report.errorMessage ?? null,
total_findings: report.totalFindings,
completed_at: report.completedAt ? report.completedAt.getTime() : null,
})
.where('id', '=', report.id.toString())
.execute();
}
toDomain(row) {
const filters = this.parseJson(row.filters_json, {});
const props = {
title: row.title,
format: ReportFormat_1.ReportFormat.fromString(row.format),
status: ReportStatus_1.ReportStatus.fromString(row.status),
filters: {
sessionId: filters.sessionId,
startDate: filters.startDate ? new Date(filters.startDate) : undefined,
endDate: filters.endDate ? new Date(filters.endDate) : undefined,
severity: filters.severity,
},
filePath: row.file_path ?? undefined,
errorMessage: row.error_message ?? undefined,
totalFindings: row.total_findings,
createdAt: new Date(row.created_at),
completedAt: row.completed_at ? new Date(row.completed_at) : undefined,
};
return Report_1.Report.reconstitute(props, UniqueId_1.UniqueId.from(row.id));
}
parseJson(json, fallback) {
try {
return JSON.parse(json);
}
catch {
return fallback;
}
}
}
exports.KyselyReportRepository = KyselyReportRepository;