25 lines
807 B
TypeScript
25 lines
807 B
TypeScript
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('userId')) throw new Error();
|
|
await this.commandBus.execute(
|
|
new DeleteAuthenticationCommand({
|
|
userId: deletedUser.userId,
|
|
}),
|
|
);
|
|
} catch (e: any) {}
|
|
}
|
|
}
|