fase(3): crawling module domain and application
This commit is contained in:
27
dist/modules/crawling/application/commands/StopCrawlCommand.js
vendored
Normal file
27
dist/modules/crawling/application/commands/StopCrawlCommand.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StopCrawlCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class StopCrawlCommand {
|
||||
constructor(repository, eventBus) {
|
||||
this.repository = repository;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(request) {
|
||||
const id = UniqueId_1.UniqueId.from(request.sessionId);
|
||||
const session = await this.repository.findById(id);
|
||||
if (!session) {
|
||||
return (0, Result_1.Err)('Session not found');
|
||||
}
|
||||
session.stop();
|
||||
await this.repository.update(session);
|
||||
const events = session.domainEvents;
|
||||
for (const event of events) {
|
||||
await this.eventBus.publish(event);
|
||||
}
|
||||
session.clearEvents();
|
||||
return (0, Result_1.Ok)(undefined);
|
||||
}
|
||||
}
|
||||
exports.StopCrawlCommand = StopCrawlCommand;
|
||||
Reference in New Issue
Block a user