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;
|
||||
21
dist/modules/scheduling/application/commands/DeleteScheduleCommand.js
vendored
Normal file
21
dist/modules/scheduling/application/commands/DeleteScheduleCommand.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DeleteScheduleCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class DeleteScheduleCommand {
|
||||
constructor(scheduleRepo, eventBus) {
|
||||
this.scheduleRepo = scheduleRepo;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(req) {
|
||||
const id = UniqueId_1.UniqueId.from(req.id);
|
||||
const schedule = await this.scheduleRepo.findById(id);
|
||||
if (!schedule)
|
||||
return (0, Result_1.Err)('Schedule not found');
|
||||
await this.scheduleRepo.delete(id);
|
||||
void this.eventBus;
|
||||
return (0, Result_1.Ok)(undefined);
|
||||
}
|
||||
}
|
||||
exports.DeleteScheduleCommand = DeleteScheduleCommand;
|
||||
24
dist/modules/scheduling/application/commands/ToggleScheduleCommand.js
vendored
Normal file
24
dist/modules/scheduling/application/commands/ToggleScheduleCommand.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ToggleScheduleCommand = void 0;
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class ToggleScheduleCommand {
|
||||
constructor(scheduleRepo, eventBus) {
|
||||
this.scheduleRepo = scheduleRepo;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
async execute(req) {
|
||||
const schedule = await this.scheduleRepo.findById(UniqueId_1.UniqueId.from(req.id));
|
||||
if (!schedule)
|
||||
return (0, Result_1.Err)('Schedule not found');
|
||||
schedule.toggle(req.enabled);
|
||||
await this.scheduleRepo.update(schedule);
|
||||
for (const event of schedule.domainEvents) {
|
||||
await this.eventBus.publish(event);
|
||||
}
|
||||
schedule.clearEvents();
|
||||
return (0, Result_1.Ok)({ id: req.id, enabled: req.enabled });
|
||||
}
|
||||
}
|
||||
exports.ToggleScheduleCommand = ToggleScheduleCommand;
|
||||
Reference in New Issue
Block a user