From eb52f9829fa472ab084901059e661f6992e21593 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 24 Feb 2026 18:47:49 -0600 Subject: [PATCH] added new ep uso in mesa --- src/mesa/mesa.controller.ts | 7 ++++++- src/mesa/mesa.service.ts | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/mesa/mesa.controller.ts b/src/mesa/mesa.controller.ts index e048d98..c655be9 100644 --- a/src/mesa/mesa.controller.ts +++ b/src/mesa/mesa.controller.ts @@ -15,7 +15,12 @@ export class MesaController { async findAllActivo() { return this.mesaService.findAllActivo(); } - + + @Get('uso') + async findActiveMesas() { + return this.mesaService.findActiveMesas(); + } + @Patch(':id') async updateActivo( @Param('id') id: number, diff --git a/src/mesa/mesa.service.ts b/src/mesa/mesa.service.ts index 03b63b7..c6189ec 100644 --- a/src/mesa/mesa.service.ts +++ b/src/mesa/mesa.service.ts @@ -119,4 +119,27 @@ export class MesaService { activo: nuevoActivo, }; } + + findActiveMesas() { + return this.mesaRepository + .createQueryBuilder('mesa') + .select([ + 'mesa.id_mesa AS id_mesa', + ` + EXISTS ( + SELECT 1 + FROM bitacora_mesa bm + WHERE bm.id_mesa = mesa.id_mesa + AND TIMESTAMPDIFF( + SECOND, + NOW(), + DATE_ADD(bm.tiempo_entrada, INTERVAL bm.tiempo_asignado MINUTE) + ) > 0 + ) AS ocupado + `, + ]) + .where('mesa.activo = 1') + .orderBy('mesa.id_mesa', 'ASC') + .getRawMany(); + } }