diff --git a/src/modules/ad/core/application/commands/update-ad/update-ad.service.ts b/src/modules/ad/core/application/commands/update-ad/update-ad.service.ts index a97d093..cc5790a 100644 --- a/src/modules/ad/core/application/commands/update-ad/update-ad.service.ts +++ b/src/modules/ad/core/application/commands/update-ad/update-ad.service.ts @@ -2,8 +2,10 @@ import { AD_REPOSITORY, INPUT_DATETIME_TRANSFORMER, } from '@modules/ad/ad.di-tokens'; +import { AdUpdatedDomainEvent } from '@modules/ad/core/domain/events/ad.domain-event'; 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 { DateTimeTransformerPort } from '../../ports/datetime-transformer.port'; import { createPropsFromCommand } from '../create-ad/create-ad.service'; @@ -16,6 +18,7 @@ export class UpdateAdService implements ICommandHandler { private readonly repository: AdRepositoryPort, @Inject(INPUT_DATETIME_TRANSFORMER) private readonly datetimeTransformer: DateTimeTransformerPort, + private readonly eventEmitter: EventEmitter2, ) {} async execute(command: UpdateAdCommand): Promise { @@ -25,5 +28,9 @@ export class UpdateAdService implements ICommandHandler { }); ad.update(createPropsFromCommand(command, this.datetimeTransformer)); await this.repository.update(ad.id, ad); + this.eventEmitter.emitAsync( + AdUpdatedDomainEvent.name, + new AdUpdatedDomainEvent(ad), + ); } } diff --git a/src/modules/ad/core/domain/ad.entity.ts b/src/modules/ad/core/domain/ad.entity.ts index 5b045c1..00ea1eb 100644 --- a/src/modules/ad/core/domain/ad.entity.ts +++ b/src/modules/ad/core/domain/ad.entity.ts @@ -6,7 +6,6 @@ import { AdDeletedDomainEvent } from './events/ad-delete.domain-event'; import { AdInvalidatedDomainEvent } from './events/ad-invalidated.domain-event'; import { AdSuspendedDomainEvent } from './events/ad-suspended.domain-event'; import { AdValidatedDomainEvent } from './events/ad-validated.domain-event'; -import { AdUpdatedDomainEvent } from './events/ad.domain-event'; import { ScheduleItemProps } from './value-objects/schedule-item.value-object'; import { WaypointProps } from './value-objects/waypoint.value-object'; @@ -111,7 +110,6 @@ export class AdEntity extends AggregateRoot { this.props.waypoints = newProps.waypoints.map((wp) => ({ ...wp })); //The ad goes back to pending status until it is validated again this.props.status = Status.PENDING; - this.addEvent(new AdUpdatedDomainEvent(this)); this.validate(); return this; };