This commit is contained in:
IO
2024-07-29 20:21:38 -06:00
parent a8794eee14
commit 1e4e7f2d65
14 changed files with 66 additions and 42 deletions
+23 -14
View File
@@ -11,15 +11,15 @@ import {
UseGuards,
Delete,
ParseIntPipe,
Query
Query,
Logger,
} from '@nestjs/common';
import { AuthGuard } from './auth.guard';
import { AuthService } from './auth.service';
import { registerDto } from './dto/registerDto.dto';
import {Roles} from '../permissions/roles.decorator'
import {RolesGuard} from '../permissions/roles.guard'
import {Role} from '../permissions/role.enum'
import { Roles } from '../permissions/roles.decorator';
import { RolesGuard } from '../permissions/roles.guard';
import { Role } from '../permissions/role.enum';
@Controller('auth')
@UseGuards(RolesGuard)
@@ -29,20 +29,22 @@ export class AuthController {
@HttpCode(HttpStatus.OK)
@Post('login')
async signIn(@Body() data: registerDto) {
Logger.debug('signIn');
const { rememberMe } = data;
return this.authService.signIn(data, rememberMe);
}
//@UseGuards()
@Post("register")
@Post('register')
//@Roles(Role.Admin)
async register(@Body() data: registerDto){
return this.authService.register(data)
async register(@Body() data: registerDto) {
Logger.debug('register user');
return this.authService.register(data);
}
//@UseGuards(AuthGuard)
@Get()
findAll() {
Logger.debug('find all users');
return this.authService.findAll();
}
@@ -50,23 +52,29 @@ export class AuthController {
findAllPaginated(
@Query('page') page: number = 1,
@Query('limit') limit: number = 10,
@Query() filters: any
@Query() filters: any,
) {
Logger.debug('find all users max 10');
page = page < 1 ? 1 : page;
limit = limit > 10 || limit < 1 ? 10 : limit;
return this.authService.findAllPaginated(page, limit,filters);
return this.authService.findAllPaginated(page, limit, filters);
}
@Get(':id_usuario')
async profile(@Param('id_usuario', ParseIntPipe) id_usuario: number) {
Logger.debug('find one user');
return this.authService.profile(id_usuario);
}
//@UseGuards(AuthGuard)
@Put(':id_usuario')
@Roles(Role.Admin)
async update(@Param('id_usuario') id_usuario: number, @Body() data: registerDto) {
async update(
@Param('id_usuario') id_usuario: number,
@Body() data: registerDto,
) {
Logger.debug('update user');
return this.authService.update(id_usuario, data);
}
@@ -74,6 +82,7 @@ export class AuthController {
@Delete(':id_usuario')
@Roles(Role.Admin)
async remove(@Param('id_usuario') id_usuario: number) {
Logger.debug('delete user');
await this.authService.remove(id_usuario);
return { message: 'User successfully deleted' };
}
@@ -81,7 +90,7 @@ export class AuthController {
@HttpCode(HttpStatus.OK)
@Post('validate')
async validateToken(@Body('token') token: string) {
Logger.debug('validate user');
return this.authService.validateToken(token);
}
}
}