teachers active
This commit is contained in:
@@ -46,8 +46,4 @@ export class ProfesorController {
|
||||
return this.profesorService.profile(id_profesor);
|
||||
}
|
||||
|
||||
@Post('filter')
|
||||
async filter(@Body() data: profesorDto) {
|
||||
return this.profesorService.filter(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,71 +171,48 @@ export class ProfesorService {
|
||||
return profesor;
|
||||
}
|
||||
|
||||
//brings teachers by filter
|
||||
async filter(filterDto: profesorDto): Promise<Profesor[]> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor');
|
||||
|
||||
if (filterDto.nombre) {
|
||||
query.andWhere('profesor.nombre like :nombre', { nombre: `%${filterDto.nombre}%` });
|
||||
}
|
||||
|
||||
if (filterDto.id_categoria !== undefined) {
|
||||
query.andWhere('profesor.id_categoria = :id_categoria', { id_categoria: filterDto.id_categoria });
|
||||
}
|
||||
|
||||
if (filterDto.extension) {
|
||||
query.andWhere('profesor.extension like :extension', { extension: `%${filterDto.extension}%` });
|
||||
}
|
||||
|
||||
if (filterDto.id_adscripcion !== undefined) {
|
||||
query.andWhere('profesor.id_adscripcion = :id_adscripcion', { id_adscripcion: filterDto.id_adscripcion });
|
||||
}
|
||||
|
||||
if (filterDto.id_edificio !== undefined) {
|
||||
query.andWhere('profesor.id_edificio = :id_edificio', { id_edificio: filterDto.id_edificio });
|
||||
}
|
||||
|
||||
if (filterDto.activo !== undefined) {
|
||||
query.andWhere('profesor.activo = :activo', { activo: filterDto.activo });
|
||||
}
|
||||
|
||||
return query.getMany();
|
||||
}
|
||||
|
||||
async findAllPaginated(
|
||||
page: number,
|
||||
limit: number,
|
||||
filters: any
|
||||
): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor')
|
||||
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor');
|
||||
|
||||
if (filters.nombre) {
|
||||
query.andWhere('profesor.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
}
|
||||
|
||||
|
||||
if (filters.adscripcion) {
|
||||
query.andWhere('profesor.adscripcion = :adscripcion', { adscripcion: filters.adscripcion });
|
||||
}
|
||||
|
||||
|
||||
if (filters.categoria) {
|
||||
query.andWhere('profesor.categoria = :categoria', { categoria: filters.categoria });
|
||||
}
|
||||
|
||||
|
||||
if (filters.edificio) {
|
||||
query.andWhere('profesor.edificio = :edificio', { edificio: filters.edificio });
|
||||
}
|
||||
|
||||
|
||||
if (typeof filters.activo !== 'undefined') {
|
||||
query.andWhere('profesor.activo = :activo', { activo: filters.activo });
|
||||
} else {
|
||||
query.orderBy('profesor.activo', 'DESC');
|
||||
}
|
||||
|
||||
query.addOrderBy('profesor.nombre', 'ASC');
|
||||
|
||||
const [profesores, total] = await query
|
||||
.skip((page - 1) * limit)
|
||||
.take(limit)
|
||||
.orderBy('profesor.nombre', 'ASC')
|
||||
.getManyAndCount();
|
||||
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
|
||||
return { profesores, total, totalPages };
|
||||
}
|
||||
|
||||
|
||||
async updateImageURL(id_profesor: number, imageUrl: string): Promise<void> {
|
||||
await this.profesorRepository.update(id_profesor, { fotografia: imageUrl });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user