Skip to content

Commit

Permalink
(#136) aplica guard e autenticacao ao app module
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueAmorim20 committed Oct 22, 2023
1 parent 7a89bc2 commit 3b5a99a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
12 changes: 11 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {}
3 changes: 3 additions & 0 deletions src/usuario/usuario.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,8 +26,10 @@ export class UsuarioController {
constructor(private readonly _service: UsuarioService) {}

@Post()
@PublicRoute()
async create(@Body() body: CreateUsuarioDto): Promise<Response<Usuario>> {
const created = await this._service.create(body);
created.senha = '';
return new HttpResponse<Usuario>(created).onCreated();
}

Expand Down

0 comments on commit 3b5a99a

Please sign in to comment.