import { DomainEvents } from '@server/shared/src/core/domain/events/DomainEvents' ; import { IHandle } from '@server/shared/src/core/domain/events/IHandle' ; import { UserCreatedEvent } from '../domain/events/UserCreatedEvent' ; import { SubscribeUserToMailingUseCase } from '../useCases/subscribeUserToMailing/SubscribeUserToMailingUseCase' ; export class AfterUserCreated implements IHandle < UserCreatedEvent > { private subscribeUserToMailing : SubscribeUserToMailingUseCase ; constructor ( subscribeUserToMailing ) { this . setupSubscriptions ( ) ; this . subscribeUserToMailing = subscribeUserToMailing ; } setupSubscriptions ( ) { DomainEvents . register ( this . onUserCreatedEvent . bind ( this ) , UserCreatedEvent . name ) ; } private async onUserCreatedEvent ( event ) { const { user } = event ; this . subscribeUserToMailing . execute ( { userId : user . id . toValue ( ) , } ) ; } }