users
This commit is contained in:
@@ -113,6 +113,32 @@ export class AuthService {
|
||||
return this.userRepository.find();
|
||||
}
|
||||
|
||||
async findAllPaginated(
|
||||
page: number,
|
||||
limit: number,
|
||||
filters: any
|
||||
): Promise<{ usuarios: User[], total: number, totalPages: number }> {
|
||||
const query = this.userRepository.createQueryBuilder('usuario');
|
||||
|
||||
if (filters.nombre) {
|
||||
query.andWhere('usuario.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
}
|
||||
|
||||
if (filters.id_tipo_usuario) {
|
||||
query.andWhere('usuario.id_tipo_usuario = :id_tipo_usuario', { id_tipo_usuario: filters.id_tipo_usuario });
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
async profile(id_usuario: number) {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { id_usuario },
|
||||
|
||||
Reference in New Issue
Block a user