added new ep called busy in equipo
This commit is contained in:
@@ -5,7 +5,7 @@ import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) {}
|
||||
constructor(private readonly equipoService: EquipoService) { }
|
||||
|
||||
@Get()
|
||||
findAll(): Promise<Equipo[]> {
|
||||
@@ -27,6 +27,11 @@ export class EquipoController {
|
||||
return this.equipoService.findOnlyUsable(+id);
|
||||
}
|
||||
|
||||
@Get('/busy')
|
||||
findOnlyBusy(): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyBusy();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): Promise<Equipo> {
|
||||
return this.equipoService.findOne(id);
|
||||
|
||||
@@ -14,7 +14,7 @@ export class EquipoService {
|
||||
@InjectRepository(Equipo)
|
||||
private readonly equipoRepository: Repository<Equipo>,
|
||||
// private readonly alumnoInscritoService: AlumnoInscritoService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
findAll() {
|
||||
return this.equipoRepository
|
||||
@@ -119,6 +119,41 @@ export class EquipoService {
|
||||
return equipos;
|
||||
}
|
||||
|
||||
async findOnlyBusy(): Promise<Equipo[]> {
|
||||
const equipos = await this.equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
.innerJoinAndSelect('equipo.plataforma', 'plataforma')
|
||||
.innerJoinAndSelect('equipo.areaUbicacion', 'area')
|
||||
.andWhere('equipo.activo = true')
|
||||
|
||||
.andWhere((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select('bitacora.id_equipo')
|
||||
.from('bitacora', 'bitacora')
|
||||
.where(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getQuery();
|
||||
|
||||
return `equipo.id_equipo IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('equipo.ubicacion', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
if (!equipos.length) {
|
||||
throw new NotFoundException('No existen equipos en uso');
|
||||
}
|
||||
|
||||
return equipos;
|
||||
}
|
||||
|
||||
async create(equipo: CreateEquipoDto) {
|
||||
const find = await this.equipoRepository.findOne({
|
||||
where: { ubicacion: equipo.ubicacion },
|
||||
|
||||
Reference in New Issue
Block a user