loger
This commit is contained in:
+23
-14
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
HttpException,
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { UsersService } from '../users/users.service';
|
||||
@@ -131,10 +132,12 @@ export class AuthService {
|
||||
const query = this.userRepository.createQueryBuilder('usuario');
|
||||
|
||||
if (filters.nombre) {
|
||||
Logger.debug('fiter by name user');
|
||||
query.andWhere('usuario.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
}
|
||||
|
||||
if (filters.id_tipo_usuario) {
|
||||
Logger.debug('fiter by id user');
|
||||
query.andWhere('usuario.id_tipo_usuario = :id_tipo_usuario', { id_tipo_usuario: filters.id_tipo_usuario });
|
||||
}
|
||||
|
||||
@@ -155,6 +158,7 @@ export class AuthService {
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
Logger.debug('user not found');
|
||||
throw new HttpException('user not found', 404);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user