fase(5): findings module complete
Some checks failed
ABE Exploratory Testing / explore (push) Has been cancelled
Some checks failed
ABE Exploratory Testing / explore (push) Has been cancelled
This commit is contained in:
33
dist/modules/findings/application/commands/EnrichFindingCommand.js
vendored
Normal file
33
dist/modules/findings/application/commands/EnrichFindingCommand.js
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EnrichFindingCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
class EnrichFindingCommand {
|
||||
constructor(repository, enricher, eventBus) {
|
||||
this.repository = repository;
|
||||
this.enricher = enricher;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(request) {
|
||||
const finding = await this.repository.findById(request.findingId);
|
||||
if (!finding) {
|
||||
return (0, Result_1.Err)(`Finding not found: ${request.findingId}`);
|
||||
}
|
||||
let enrichment;
|
||||
try {
|
||||
enrichment = await this.enricher.enrich(finding);
|
||||
}
|
||||
catch (e) {
|
||||
return (0, Result_1.Err)(`Enrichment failed: ${e instanceof Error ? e.message : String(e)}`);
|
||||
}
|
||||
finding.enrich(enrichment);
|
||||
await this.repository.update(finding);
|
||||
const events = finding.domainEvents;
|
||||
for (const event of events) {
|
||||
await this.eventBus.publish(event);
|
||||
}
|
||||
finding.clearEvents();
|
||||
return (0, Result_1.Ok)({ findingId: finding.id.toString() });
|
||||
}
|
||||
}
|
||||
exports.EnrichFindingCommand = EnrichFindingCommand;
|
||||
Reference in New Issue
Block a user