mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-04-05 05:00:21 +00:00
user deleted message handler
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user