fase(19): scheduling module refactor
This commit is contained in:
32
dist/modules/scheduling/application/commands/CreateScheduleCommand.js
vendored
Normal file
32
dist/modules/scheduling/application/commands/CreateScheduleCommand.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateScheduleCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const Schedule_1 = require("../../domain/entities/Schedule");
|
||||
class CreateScheduleCommand {
|
||||
constructor(scheduleRepo, eventBus) {
|
||||
this.scheduleRepo = scheduleRepo;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(req) {
|
||||
const result = Schedule_1.Schedule.create(req);
|
||||
if (!result.ok)
|
||||
return (0, Result_1.Err)(result.error);
|
||||
const schedule = result.value;
|
||||
await this.scheduleRepo.save(schedule);
|
||||
for (const event of schedule.domainEvents) {
|
||||
await this.eventBus.publish(event);
|
||||
}
|
||||
schedule.clearEvents();
|
||||
return (0, Result_1.Ok)({
|
||||
id: schedule.id.toString(),
|
||||
name: schedule.name,
|
||||
url: schedule.url,
|
||||
cronExpression: schedule.cronExpression.value,
|
||||
enabled: schedule.enabled,
|
||||
nextRunAt: schedule.nextRunAt,
|
||||
createdAt: schedule.createdAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.CreateScheduleCommand = CreateScheduleCommand;
|
||||
Reference in New Issue
Block a user