use new integration events

This commit is contained in:
sbriat 2023-07-24 16:02:49 +02:00
parent 66bfa89e8f
commit 3d746df9bc
4 changed files with 11 additions and 11 deletions

View File

@ -13,10 +13,10 @@ export class UserDeletedMessageHandler {
public async userDeleted(message: string) { public async userDeleted(message: string) {
const deletedUser = JSON.parse(message); const deletedUser = JSON.parse(message);
try { try {
if (!deletedUser.hasOwnProperty('userId')) throw new Error(); if (!deletedUser.hasOwnProperty('id')) throw new Error();
await this.commandBus.execute( await this.commandBus.execute(
new DeleteAuthenticationCommand({ new DeleteAuthenticationCommand({
userId: deletedUser.userId, userId: deletedUser.id,
}), }),
); );
} catch (e: any) {} } catch (e: any) {}

View File

@ -14,11 +14,11 @@ export class UserUpdatedMessageHandler {
public async userUpdated(message: string) { public async userUpdated(message: string) {
const updatedUser = JSON.parse(message); const updatedUser = JSON.parse(message);
try { try {
if (!updatedUser.hasOwnProperty('userId')) throw new Error(); if (!updatedUser.hasOwnProperty('id')) throw new Error();
if (updatedUser.hasOwnProperty('email') && updatedUser.email) { if (updatedUser.hasOwnProperty('email') && updatedUser.email) {
await this.commandBus.execute( await this.commandBus.execute(
new UpdateUsernameCommand({ new UpdateUsernameCommand({
userId: updatedUser.userId, userId: updatedUser.id,
username: { username: {
name: updatedUser.email, name: updatedUser.email,
type: Type.EMAIL, type: Type.EMAIL,
@ -29,7 +29,7 @@ export class UserUpdatedMessageHandler {
if (updatedUser.hasOwnProperty('phone') && updatedUser.phone) { if (updatedUser.hasOwnProperty('phone') && updatedUser.phone) {
await this.commandBus.execute( await this.commandBus.execute(
new UpdateUsernameCommand({ new UpdateUsernameCommand({
userId: updatedUser.userId, userId: updatedUser.if,
username: { username: {
name: updatedUser.phone, name: updatedUser.phone,
type: Type.PHONE, type: Type.PHONE,

View File

@ -2,10 +2,10 @@ import { UserDeletedMessageHandler } from '@modules/authentication/interface/mes
import { CommandBus } from '@nestjs/cqrs'; import { CommandBus } from '@nestjs/cqrs';
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
const userDeletedMessage = '{"userId":"2436d413-b7c7-429e-9792-b78edc17b3ca"}'; const userDeletedMessage = '{"id":"2436d413-b7c7-429e-9792-b78edc17b3ca"}';
const userIdNotProvidedDeletedMessage = const userIdNotProvidedDeletedMessage =
'{"user":"2436d413-b7c7-429e-9792-b78edc17b300"}'; '{"userId":"2436d413-b7c7-429e-9792-b78edc17b300"}';
const mockCommandBus = { const mockCommandBus = {
execute: jest.fn().mockImplementationOnce(() => 'john.doe@email.com'), execute: jest.fn().mockImplementationOnce(() => 'john.doe@email.com'),

View File

@ -3,16 +3,16 @@ import { CommandBus } from '@nestjs/cqrs';
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
const userEmailUpdatedMessage = const userEmailUpdatedMessage =
'{"userId":"2436d413-b7c7-429e-9792-b78edc17b3ca","email":"new-john.doe@email.com"}'; '{"id":"2436d413-b7c7-429e-9792-b78edc17b3ca","email":"new-john.doe@email.com"}';
const userPhoneUpdatedMessage = const userPhoneUpdatedMessage =
'{"userId":"2436d413-b7c7-429e-9792-b78edc17b3ca","phone":"+33611224455"}'; '{"id":"2436d413-b7c7-429e-9792-b78edc17b3ca","phone":"+33611224455"}';
const userBirthDateUpdatedMessage = const userBirthDateUpdatedMessage =
'{"userId":"2436d413-b7c7-429e-9792-b78edc17b3ca","birthDate":"1976-10-23"}'; '{"id":"2436d413-b7c7-429e-9792-b78edc17b3ca","birthDate":"1976-10-23"}';
const userIdNotProvidedUpdatedMessage = const userIdNotProvidedUpdatedMessage =
'{"user":"2436d413-b7c7-429e-9792-b78edc17b300","email":"new-john.doe@email.com"}'; '{"userId":"2436d413-b7c7-429e-9792-b78edc17b300","email":"new-john.doe@email.com"}';
const mockCommandBus = { const mockCommandBus = {
execute: jest execute: jest