fase(15): reporting module with pdf generation
This commit is contained in:
33
dist/modules/reporting/application/commands/GenerateReportCommand.js
vendored
Normal file
33
dist/modules/reporting/application/commands/GenerateReportCommand.js
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GenerateReportCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const Report_1 = require("../../domain/entities/Report");
|
||||
const ReportFormat_1 = require("../../domain/value-objects/ReportFormat");
|
||||
class GenerateReportCommand {
|
||||
constructor(reportRepository, eventBus) {
|
||||
this.reportRepository = reportRepository;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(request) {
|
||||
let format;
|
||||
try {
|
||||
format = ReportFormat_1.ReportFormat.fromString(request.format);
|
||||
}
|
||||
catch {
|
||||
return (0, Result_1.Err)(`Invalid format: ${request.format}`);
|
||||
}
|
||||
const report = Report_1.Report.create({
|
||||
title: request.title,
|
||||
format,
|
||||
filters: request.filters ?? {},
|
||||
});
|
||||
await this.reportRepository.save(report);
|
||||
const events = report.clearEvents();
|
||||
for (const event of events) {
|
||||
await this.eventBus.publish(event);
|
||||
}
|
||||
return (0, Result_1.Ok)({ reportId: report.id.toString(), status: report.status.value });
|
||||
}
|
||||
}
|
||||
exports.GenerateReportCommand = GenerateReportCommand;
|
||||
Reference in New Issue
Block a user