add get user
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -108,4 +108,20 @@ export class AuthService {
|
||||
throw new UnauthorizedException('validation token failed');
|
||||
}
|
||||
}
|
||||
|
||||
async findAll(): Promise<User[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user