25 lines
965 B
JavaScript
25 lines
965 B
JavaScript
"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;
|