From a34d51a524a71b458d9a8d8f8d288183915b03c7 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Fri, 23 Dec 2022 15:29:53 +0100 Subject: [PATCH] fix validation --- .env | 2 -- .env.dist | 2 -- .../adapters/primaries/auth-messager.controller.ts | 4 ++-- .../auth/adapters/primaries/rpc.validation-pipe.ts | 14 ++++++++++++++ src/modules/auth/auth.module.ts | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 src/modules/auth/adapters/primaries/rpc.validation-pipe.ts diff --git a/.env b/.env index 9475988..42e21b7 100644 --- a/.env +++ b/.env @@ -7,8 +7,6 @@ SERVICE_PORT=5002 DATABASE_URL="postgresql://auth:auth@v3-auth-db:5432/auth?schema=public" # RABBIT MQ -RMQ_EXCHANGE_NAME=user -RMQ_EXCHANGE_TYPE=topic RMQ_URI=amqp://v3-gateway-broker:5672 # POSTGRES diff --git a/.env.dist b/.env.dist index 89d3ce5..20f7a25 100644 --- a/.env.dist +++ b/.env.dist @@ -7,8 +7,6 @@ SERVICE_PORT=5002 DATABASE_URL="postgresql://auth:auth@db:5432/auth?schema=public" # RABBIT MQ -RMQ_EXCHANGES=user -RMQ_EXCHANGE_TYPE=topic RMQ_URI=amqp://localhost:5672 # POSTGRES diff --git a/src/modules/auth/adapters/primaries/auth-messager.controller.ts b/src/modules/auth/adapters/primaries/auth-messager.controller.ts index 12685b3..7331e7b 100644 --- a/src/modules/auth/adapters/primaries/auth-messager.controller.ts +++ b/src/modules/auth/adapters/primaries/auth-messager.controller.ts @@ -13,7 +13,7 @@ export class AuthMessagerController { @RabbitSubscribe({ exchange: 'user', - routingKey: 'user.update', + routingKey: 'update', queue: 'auth-user-update', }) public async userUpdatedHandler(message: string) { @@ -41,7 +41,7 @@ export class AuthMessagerController { @RabbitSubscribe({ exchange: 'user', - routingKey: 'user.delete', + routingKey: 'delete', queue: 'auth-user-delete', }) public async userDeletedHandler(message: string) { diff --git a/src/modules/auth/adapters/primaries/rpc.validation-pipe.ts b/src/modules/auth/adapters/primaries/rpc.validation-pipe.ts new file mode 100644 index 0000000..f2b8c19 --- /dev/null +++ b/src/modules/auth/adapters/primaries/rpc.validation-pipe.ts @@ -0,0 +1,14 @@ +import { Injectable, ValidationPipe } from '@nestjs/common'; +import { RpcException } from '@nestjs/microservices'; + +@Injectable() +export class RpcValidationPipe extends ValidationPipe { + createExceptionFactory() { + return (validationErrors = []) => { + return new RpcException({ + code: 3, + message: this.flattenValidationErrors(validationErrors), + }); + }; + } +} diff --git a/src/modules/auth/auth.module.ts b/src/modules/auth/auth.module.ts index 7f0e887..e3e0e1c 100644 --- a/src/modules/auth/auth.module.ts +++ b/src/modules/auth/auth.module.ts @@ -25,8 +25,8 @@ import { AuthMessagerController } from './adapters/primaries/auth-messager.contr useFactory: async (configService: ConfigService) => ({ exchanges: [ { - name: configService.get('RMQ_EXCHANGE_NAME'), - type: configService.get('RMQ_EXCHANGE_TYPE'), + name: 'user', + type: 'topic', }, ], uri: configService.get('RMQ_URI'),