auth
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user