diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 2427563..b086964 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -9,7 +9,8 @@ import { Put, Request, UseGuards, - Delete + Delete, + ParseIntPipe } from '@nestjs/common'; import { AuthGuard } from './auth.guard'; import { AuthService } from './auth.service'; @@ -38,9 +39,14 @@ export class AuthController { } //@UseGuards(AuthGuard) - @Get('profile') - async getProfile(@Request() req) { - return req.user; + @Get() + findAll() { + return this.authService.findAll(); + } + + @Get(':id_user') + async profile(@Param('id_user', ParseIntPipe) id_user: number) { + return this.authService.profile(id_user); } //@UseGuards(AuthGuard) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 6dd715f..f3d0e2d 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -108,4 +108,20 @@ export class AuthService { throw new UnauthorizedException('validation token failed'); } } + + async findAll(): Promise { + return this.userRepository.find(); + } + + async profile(id_usuario: number) { + const user = await this.userRepository.findOne({ + where: { id_usuario }, + }); + + if (!user) { + throw new HttpException('user not found', 404); + } + + return user; + } }