36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ResolveFindingCommand = void 0;
|
|
const Result_1 = require("../../../../shared/domain/Result");
|
|
class ResolveFindingCommand {
|
|
constructor(repository, eventBus) {
|
|
this.repository = repository;
|
|
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}`);
|
|
}
|
|
switch (request.action) {
|
|
case 'resolve':
|
|
finding.resolve();
|
|
break;
|
|
case 'close':
|
|
finding.close();
|
|
break;
|
|
case 'investigate':
|
|
finding.investigate();
|
|
break;
|
|
}
|
|
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(), status: finding.status.value });
|
|
}
|
|
}
|
|
exports.ResolveFindingCommand = ResolveFindingCommand;
|