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:
50
dist/modules/findings/application/commands/CreateFindingCommand.js
vendored
Normal file
50
dist/modules/findings/application/commands/CreateFindingCommand.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateFindingCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const Finding_1 = require("../../domain/entities/Finding");
|
||||
const Severity_1 = require("../../domain/value-objects/Severity");
|
||||
const FindingType_1 = require("../../domain/value-objects/FindingType");
|
||||
const Evidence_1 = require("../../domain/value-objects/Evidence");
|
||||
class CreateFindingCommand {
|
||||
constructor(repository, eventBus) {
|
||||
this.repository = repository;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(request) {
|
||||
let severity;
|
||||
let type;
|
||||
try {
|
||||
severity = Severity_1.Severity.fromString(request.anomaly.severity);
|
||||
type = FindingType_1.FindingType.fromString(request.anomaly.type);
|
||||
}
|
||||
catch (e) {
|
||||
return (0, Result_1.Err)(e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
const evidence = Evidence_1.Evidence.create({
|
||||
screenshotPath: request.anomaly.evidence.screenshotPath,
|
||||
domSnapshotPath: request.anomaly.evidence.domSnapshotPath,
|
||||
httpLog: request.anomaly.evidence.httpLog,
|
||||
rawErrors: request.anomaly.evidence.rawErrors,
|
||||
});
|
||||
const finding = Finding_1.Finding.create({
|
||||
sessionId: request.sessionId,
|
||||
severity,
|
||||
type,
|
||||
description: request.anomaly.description,
|
||||
evidence,
|
||||
actionTrace: request.anomaly.actionTrace,
|
||||
browser: request.anomaly.browser,
|
||||
browserVersion: request.anomaly.browserVersion,
|
||||
aiEnrichment: request.anomaly.aiEnrichment,
|
||||
});
|
||||
await this.repository.save(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.CreateFindingCommand = CreateFindingCommand;
|
||||
Reference in New Issue
Block a user