import { Injectable } from '@nestjs/common'; import { CommandBus } from '@nestjs/cqrs'; import { RabbitSubscribe } from '@mobicoop/message-broker-module'; import { DeleteAuthenticationCommand } from '@modules/authentication/core/application/commands/delete-authentication/delete-authentication.command'; @Injectable() export class UserDeletedMessageHandler { constructor(private readonly commandBus: CommandBus) {} @RabbitSubscribe({ name: 'userDeleted', }) public async userDeleted(message: string) { const deletedUser = JSON.parse(message); try { if (!deletedUser.hasOwnProperty('id')) throw new Error(); await this.commandBus.execute( new DeleteAuthenticationCommand({ userId: deletedUser.id, }), ); } catch (e: any) {} } }