From e28d534edf151f7eb9313f78dff42b41e89f31ae Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 4 Mar 2026 18:19:36 -0600 Subject: [PATCH] new ep usoWhitout --- src/mesa/mesa.controller.ts | 17 ++++++++++++----- src/mesa/mesa.service.ts | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/mesa/mesa.controller.ts b/src/mesa/mesa.controller.ts index a713b76..92f69cf 100644 --- a/src/mesa/mesa.controller.ts +++ b/src/mesa/mesa.controller.ts @@ -11,26 +11,33 @@ export class MesaController { constructor(private readonly mesaService: MesaService) { } @UseGuards(JwtAuthGuard, RolesGuard) - @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) @Get() async findAll() { return this.mesaService.findAll(); } @UseGuards(JwtAuthGuard, RolesGuard) - @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) @Get('activo') async findAllActivo() { return this.mesaService.findAllActivo(); } - + @UseGuards(JwtAuthGuard, RolesGuard) - @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) @Get('uso') async findActiveMesas() { return this.mesaService.findActiveMesas(); } + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) + @Get('usoWhitout') + async findActiveMesasWhitoudOcupado() { + return this.mesaService.findActiveMesasWhitoudOcupado(); + } + @UseGuards(JwtAuthGuard, RolesGuard) @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Patch(':id') @@ -42,7 +49,7 @@ export class MesaController { } @UseGuards(JwtAuthGuard, RolesGuard) - @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL) + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL) @Patch(':id/activo') toggleActivo(@Param('id') id: number) { return this.mesaService.toggleActivo(+id); diff --git a/src/mesa/mesa.service.ts b/src/mesa/mesa.service.ts index c6189ec..07390fb 100644 --- a/src/mesa/mesa.service.ts +++ b/src/mesa/mesa.service.ts @@ -142,4 +142,27 @@ export class MesaService { .orderBy('mesa.id_mesa', 'ASC') .getRawMany(); } + + findActiveMesasWhitoudOcupado() { + return this.mesaRepository + .createQueryBuilder('mesa') + .select([ + 'mesa.id_mesa AS id_mesa', + ]) + .where('mesa.activo = 1') + .andWhere(` + NOT 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 + ) + `) + .orderBy('mesa.id_mesa', 'ASC') + .getRawMany(); + } }