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,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Report = void 0;
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
const ReportStatus_1 = require("../value-objects/ReportStatus");
const ReportRequested_1 = require("../events/ReportRequested");
const ReportGenerated_1 = require("../events/ReportGenerated");
const ReportFailed_1 = require("../events/ReportFailed");
class Report extends AggregateRoot_1.AggregateRoot {
static create(props, id) {
const reportId = id ?? UniqueId_1.UniqueId.create();
const report = new Report({
...props,
status: ReportStatus_1.ReportStatus.pending(),
totalFindings: 0,
createdAt: new Date(),
}, reportId);
report.addDomainEvent(new ReportRequested_1.ReportRequested(reportId.toString(), {
title: props.title,
format: props.format.value,
filters: props.filters,
}));
return report;
}
static reconstitute(props, id) {
return new Report(props, id);
}
get title() { return this.props.title; }
get format() { return this.props.format; }
get status() { return this.props.status; }
get filters() { return this.props.filters; }
get filePath() { return this.props.filePath; }
get errorMessage() { return this.props.errorMessage; }
get totalFindings() { return this.props.totalFindings; }
get createdAt() { return this.props.createdAt; }
get completedAt() { return this.props.completedAt; }
markGenerating() {
this.props.status = ReportStatus_1.ReportStatus.generating();
}
markReady(filePath, totalFindings) {
this.props.status = ReportStatus_1.ReportStatus.ready();
this.props.filePath = filePath;
this.props.totalFindings = totalFindings;
this.props.completedAt = new Date();
this.addDomainEvent(new ReportGenerated_1.ReportGenerated(this.id.toString(), {
filePath,
totalFindings,
format: this.props.format.value,
}));
}
markFailed(errorMessage) {
this.props.status = ReportStatus_1.ReportStatus.failed();
this.props.errorMessage = errorMessage;
this.props.completedAt = new Date();
this.addDomainEvent(new ReportFailed_1.ReportFailed(this.id.toString(), { errorMessage }));
}
}
exports.Report = Report;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportFailed = void 0;
const crypto_1 = require("crypto");
class ReportFailed {
constructor(aggregateId, payload) {
this.aggregateId = aggregateId;
this.payload = payload;
this.eventId = (0, crypto_1.randomUUID)();
this.eventName = 'reporting.report_failed';
this.occurredOn = new Date();
}
}
exports.ReportFailed = ReportFailed;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportGenerated = void 0;
const crypto_1 = require("crypto");
class ReportGenerated {
constructor(aggregateId, payload) {
this.aggregateId = aggregateId;
this.payload = payload;
this.eventId = (0, crypto_1.randomUUID)();
this.eventName = 'reporting.report_generated';
this.occurredOn = new Date();
}
}
exports.ReportGenerated = ReportGenerated;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportRequested = void 0;
const crypto_1 = require("crypto");
class ReportRequested {
constructor(aggregateId, payload) {
this.aggregateId = aggregateId;
this.payload = payload;
this.eventId = (0, crypto_1.randomUUID)();
this.eventName = 'reporting.report_requested';
this.occurredOn = new Date();
}
}
exports.ReportRequested = ReportRequested;

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateRange = void 0;
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
class DateRange extends ValueObject_1.ValueObject {
get startDate() { return this.props.startDate; }
get endDate() { return this.props.endDate; }
static create(startDate, endDate) {
if (startDate > endDate)
throw new Error('startDate must be before endDate');
return new DateRange({ startDate, endDate });
}
}
exports.DateRange = DateRange;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportFormat = void 0;
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
class ReportFormat extends ValueObject_1.ValueObject {
get value() { return this.props.value; }
static html() { return new ReportFormat({ value: 'html' }); }
static json() { return new ReportFormat({ value: 'json' }); }
static pdf() { return new ReportFormat({ value: 'pdf' }); }
static fromString(s) {
if (s === 'html' || s === 'json' || s === 'pdf') {
return new ReportFormat({ value: s });
}
throw new Error(`Invalid report format: ${s}`);
}
}
exports.ReportFormat = ReportFormat;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportStatus = void 0;
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
class ReportStatus extends ValueObject_1.ValueObject {
get value() { return this.props.value; }
static pending() { return new ReportStatus({ value: 'pending' }); }
static generating() { return new ReportStatus({ value: 'generating' }); }
static ready() { return new ReportStatus({ value: 'ready' }); }
static failed() { return new ReportStatus({ value: 'failed' }); }
static fromString(s) {
if (s === 'pending' || s === 'generating' || s === 'ready' || s === 'failed') {
return new ReportStatus({ value: s });
}
throw new Error(`Invalid report status: ${s}`);
}
}
exports.ReportStatus = ReportStatus;