added new logic in findallActivo

This commit is contained in:
2026-02-24 17:37:39 -06:00
parent f9a12d5c0d
commit c63f59593c
2 changed files with 32 additions and 6 deletions
+1 -2
View File
@@ -14,8 +14,7 @@ export class BitacoraMesaService {
) { } ) { }
async assignment(dto: CreateBitacoraMesaDto) { async assignment(dto: CreateBitacoraMesaDto) {
// VALIDAR: el alumno ya tiene una mesa activa
const alumnoConMesa = await this.bitacoraMesaRepository const alumnoConMesa = await this.bitacoraMesaRepository
.createQueryBuilder('bitacora') .createQueryBuilder('bitacora')
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', { .where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
+31 -4
View File
@@ -38,15 +38,42 @@ export class MesaService {
}); });
} }
async findAll(): Promise<Mesa[]> { async findAll(): Promise<Mesa[]> {
return await this.mesaRepository.find(); return await this.mesaRepository.find();
} }
async findAllActivo(): Promise<Mesa[]> { 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) { async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {