71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { Equipo } from './entities/equipo.entity';
|
|
import { AlumnoInscritoService } from 'src/alumno_inscrito/alumno_inscrito.service';
|
|
|
|
@Injectable()
|
|
export class EquipoService {
|
|
constructor(
|
|
@InjectRepository(Equipo)
|
|
private readonly equipoRepository: Repository<Equipo>,
|
|
// private readonly alumnoInscritoService: AlumnoInscritoService,
|
|
) {}
|
|
|
|
findAll() {
|
|
return this.equipoRepository.find({
|
|
relations: ['areaUbicacion', 'plataforma'],
|
|
});
|
|
}
|
|
|
|
findActive() {
|
|
return this.equipoRepository
|
|
.createQueryBuilder('equipo')
|
|
.where('equipo.activo = :activo', { activo: 1 })
|
|
.innerJoinAndSelect('equipo.plataforma', 'p')
|
|
.innerJoinAndSelect('equipo.areaUbicacion', 'a')
|
|
.orderBy('equipo.ubicacion', 'ASC')
|
|
.getMany();
|
|
}
|
|
|
|
findDisable() {
|
|
return this.equipoRepository
|
|
.createQueryBuilder('equipo')
|
|
.where('equipo.activo = :activo', { activo: 0 })
|
|
.innerJoinAndSelect('equipo.plataforma', 'p')
|
|
.innerJoinAndSelect('equipo.areaUbicacion', 'a')
|
|
.orderBy('equipo.ubicacion', 'ASC')
|
|
.getMany();
|
|
}
|
|
|
|
async findOne(id_equipo: number): Promise<Equipo> {
|
|
const equipo = await this.equipoRepository.findOne({
|
|
where: { id_equipo },
|
|
});
|
|
if (!equipo) {
|
|
throw new NotFoundException('not found');
|
|
}
|
|
return equipo;
|
|
}
|
|
|
|
async findOnlyUsable(id_cuenta: number): Promise<Equipo[]> {
|
|
const equipos = await this.equipoRepository
|
|
.createQueryBuilder('equipo')
|
|
.innerJoinAndSelect('equipo.plataforma', 'plataforma')
|
|
.innerJoin('plataforma.alumnos_inscritos', 'ai')
|
|
.innerJoin('ai.alumno', 'alumno')
|
|
.innerJoin('ai.periodo', 'periodo')
|
|
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
|
.andWhere("periodo.activo = b'1'")
|
|
.andWhere("equipo.activo = b'1'")
|
|
.getMany();
|
|
|
|
if (equipos.length === 0) {
|
|
throw new NotFoundException('No usable equipment found');
|
|
}
|
|
|
|
return equipos;
|
|
}
|
|
}
|
|
//IO
|