feat(pause ad): emit update event after pause ad
This commit is contained in:
parent
2ce64cd1c4
commit
eeddd54139
|
@ -1,19 +1,30 @@
|
||||||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||||
import { Inject } from '@nestjs/common';
|
import { Inject } from '@nestjs/common';
|
||||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { AdRepositoryPort } from '../../ports/ad.repository.port';
|
import { AdRepositoryPort } from '../../ports/ad.repository.port';
|
||||||
import { PauseAdCommand } from './pause-ad.command';
|
import { PauseAdCommand } from './pause-ad.command';
|
||||||
|
import { AdUpdatedDomainEvent } from '@modules/ad/core/domain/events/ad.domain-event';
|
||||||
|
|
||||||
@CommandHandler(PauseAdCommand)
|
@CommandHandler(PauseAdCommand)
|
||||||
export class PauseAdService implements ICommandHandler {
|
export class PauseAdService implements ICommandHandler {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(AD_REPOSITORY)
|
@Inject(AD_REPOSITORY)
|
||||||
private readonly adRepository: AdRepositoryPort,
|
private readonly adRepository: AdRepositoryPort,
|
||||||
|
private readonly eventEmitter: EventEmitter2,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: PauseAdCommand): Promise<void> {
|
async execute(command: PauseAdCommand): Promise<void> {
|
||||||
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();
|
ad.pause();
|
||||||
await this.adRepository.update(ad.id, ad);
|
await this.adRepository.update(ad.id, ad);
|
||||||
|
this.eventEmitter.emitAsync(
|
||||||
|
AdUpdatedDomainEvent.name,
|
||||||
|
new AdUpdatedDomainEvent(ad),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue