From eeddd54139852cea9a0655db280572bb803fd954 Mon Sep 17 00:00:00 2001 From: Fanch Date: Thu, 16 May 2024 15:40:03 +0200 Subject: [PATCH] feat(pause ad): emit update event after pause ad --- .../commands/pause-ad/pause-ad.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/ad/core/application/commands/pause-ad/pause-ad.service.ts b/src/modules/ad/core/application/commands/pause-ad/pause-ad.service.ts index fecfe01..356f66d 100644 --- a/src/modules/ad/core/application/commands/pause-ad/pause-ad.service.ts +++ b/src/modules/ad/core/application/commands/pause-ad/pause-ad.service.ts @@ -1,19 +1,30 @@ import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens'; import { Inject } from '@nestjs/common'; import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; +import { EventEmitter2 } from '@nestjs/event-emitter'; import { AdRepositoryPort } from '../../ports/ad.repository.port'; import { PauseAdCommand } from './pause-ad.command'; +import { AdUpdatedDomainEvent } from '@modules/ad/core/domain/events/ad.domain-event'; @CommandHandler(PauseAdCommand) export class PauseAdService implements ICommandHandler { constructor( @Inject(AD_REPOSITORY) private readonly adRepository: AdRepositoryPort, + private readonly eventEmitter: EventEmitter2, ) {} async execute(command: PauseAdCommand): Promise { - const ad = await this.adRepository.findOneById(command.id); + const ad = await this.adRepository.findOneById(command.id, { + // TODO: waypoints and schedule needed for event, should be optional if no modif on them ... + waypoints: true, + schedule: true, + }); ad.pause(); await this.adRepository.update(ad.id, ad); + this.eventEmitter.emitAsync( + AdUpdatedDomainEvent.name, + new AdUpdatedDomainEvent(ad), + ); } }