diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index cacd18a..3bd0c92 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -77,11 +77,17 @@ export class AuthController { } @Get('page') - findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10, @Query() filters: any) { + findAllPaginated( + @Query('page') page: number = 1, + @Query('limit') limit: number = 10, + @Query('nombreUsuario') nombreUsuario?: string, + @Query('tipoUsuario') tipoUsuario?: string + ) { page = page < 1 ? 1 : page; limit = limit > 10 || limit < 1 ? 10 : limit; - return this.authService.findAllPaginated(page, limit); + return this.authService.findAllPaginated(page, limit, nombreUsuario, tipoUsuario); } + } \ No newline at end of file diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 2dc5f76..5b8c0b6 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -128,17 +128,27 @@ export class AuthService { async findAllPaginated( page: number, limit: number, + nombreUsuario?: string, + tipoUsuario?: string ): Promise<{ usuarios: User[], total: number, totalPages: number }> { const query = this.userRepository.createQueryBuilder('usuario'); - + + if (nombreUsuario) { + query.andWhere('usuario.nombre LIKE :nombreUsuario', { nombreUsuario: `%${nombreUsuario}%` }); + } + + if (tipoUsuario) { + query.andWhere('usuario.id_tipo_usuario = :tipoUsuario', { tipoUsuario }); + } + const [usuarios, total] = await query .skip((page - 1) * limit) .take(limit) .orderBy('usuario.nombre', 'ASC') .getManyAndCount(); - + const totalPages = Math.ceil(total / limit); - + return { usuarios, total, totalPages }; }