added new logic in findallActivo
This commit is contained in:
@@ -14,8 +14,7 @@ export class BitacoraMesaService {
|
||||
) { }
|
||||
|
||||
async assignment(dto: CreateBitacoraMesaDto) {
|
||||
|
||||
// VALIDAR: el alumno ya tiene una mesa activa
|
||||
|
||||
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||
|
||||
@@ -38,15 +38,42 @@ export class MesaService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async findAll(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find();
|
||||
}
|
||||
|
||||
|
||||
async findAllActivo(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find({ where: { activo: true } });
|
||||
const mesas = await this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
|
||||
.andWhere('mesa.activo = true')
|
||||
|
||||
.andWhere((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select('bitacora_mesa.id_mesa')
|
||||
.from('bitacora_mesa', 'bitacora_mesa')
|
||||
.where(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora_mesa.tiempo_entrada, INTERVAL bitacora_mesa.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getQuery();
|
||||
|
||||
return `mesa.id_mesa NOT IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
if (!mesas.length) {
|
||||
throw new NotFoundException('No usable table found');
|
||||
}
|
||||
|
||||
return mesas;
|
||||
}
|
||||
|
||||
async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {
|
||||
|
||||
Reference in New Issue
Block a user