From 3b5a99aa97cd93bd11f1cd3314bcf0cab93bb476 Mon Sep 17 00:00:00 2001 From: Henrique Melo Date: Sun, 22 Oct 2023 20:11:32 -0300 Subject: [PATCH] (#136) aplica guard e autenticacao ao app module --- src/app.controller.ts | 2 ++ src/app.module.ts | 12 +++++++++++- src/usuario/usuario.controller.ts | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app.controller.ts b/src/app.controller.ts index cea3966..ded1087 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,11 +1,13 @@ import { Controller, Get } from '@nestjs/common'; import { AppService } from './app.service'; +import { PublicRoute } from './shared/decorators/public-route.decorator'; @Controller() export class AppController { constructor(private readonly service: AppService) {} @Get('health-check') + @PublicRoute() healthCheck() { return this.service.healthCheck(); } diff --git a/src/app.module.ts b/src/app.module.ts index 194408c..236a21d 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,8 +1,11 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; +import { APP_GUARD } from '@nestjs/core'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { AutenticacaoModule } from './autenticacao/autenticacao.module'; +import { JwtAuthGuard } from './autenticacao/jwt-auth.guard'; import { DbModule } from './config/db/db.module'; import { DbService } from './config/db/db.service'; import { UsuarioModule } from './usuario/usuario.module'; @@ -21,8 +24,15 @@ const ENV = process.env.NODE_ENV; }), DbModule, UsuarioModule, + AutenticacaoModule, ], controllers: [AppController], - providers: [AppService], + providers: [ + AppService, + { + provide: APP_GUARD, + useClass: JwtAuthGuard, + }, + ], }) export class AppModule {} diff --git a/src/usuario/usuario.controller.ts b/src/usuario/usuario.controller.ts index 225e19d..b9f1b2d 100644 --- a/src/usuario/usuario.controller.ts +++ b/src/usuario/usuario.controller.ts @@ -11,6 +11,7 @@ import { HttpResponse } from '../shared/classes/http-response'; import { Filtering, Filtrate } from '../shared/decorators/filtrate.decorator'; import { Ordenate, Ordering } from '../shared/decorators/ordenate.decorator'; import { Paginate, Pagination } from '../shared/decorators/paginate.decorator'; +import { PublicRoute } from '../shared/decorators/public-route.decorator'; import { Response } from '../shared/interceptors/data-transform.interceptor'; import { ResponsePaginate } from '../shared/interfaces/response-paginate.interface'; import { IdValidator } from '../shared/validators/id.validator'; @@ -25,8 +26,10 @@ export class UsuarioController { constructor(private readonly _service: UsuarioService) {} @Post() + @PublicRoute() async create(@Body() body: CreateUsuarioDto): Promise> { const created = await this._service.create(body); + created.senha = ''; return new HttpResponse(created).onCreated(); }