This commit is contained in:
IO
2024-06-26 22:21:24 -06:00
parent 8e5d2c000d
commit bfd9d7da0d
2 changed files with 21 additions and 5 deletions
+8 -2
View File
@@ -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);
}
}
+13 -3
View File
@@ -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 };
}