import { Injectable , InternalServerErrorException } from '@nestjs/common' ; import { EventEmitter2 } from '@nestjs/event-emitter' ; import { TaskEither , tryCatch } from 'fp-ts/lib/TaskEither' ; import { DomainEvent } from '../domain/domainEvent' ; @ Injectable ( ) export class DomainEventPublisher { constructor ( private eventEmitter ) { } publishEvent = ( domainEvent ) : TaskEither < Error , void > => { return tryCatch ( async ( ) => { this . eventEmitter . emit ( domainEvent . eventKey , domainEvent . payload ) ; } , ( reason ) => new InternalServerErrorException ( ) ) ; } ; }