diff --git a/src/bitacora_mesa/bitacora_mesa.controller.ts b/src/bitacora_mesa/bitacora_mesa.controller.ts index 2ed137c..57852a5 100644 --- a/src/bitacora_mesa/bitacora_mesa.controller.ts +++ b/src/bitacora_mesa/bitacora_mesa.controller.ts @@ -1,4 +1,12 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { + Controller, + Get, + Post, + Body, + Patch, + Param, + Delete, +} from '@nestjs/common'; import { BitacoraMesaService } from './bitacora_mesa.service'; import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto'; @@ -20,4 +28,9 @@ export class BitacoraMesaController { findOne(@Param('id') id: string) { return this.bitacoraMesaService.findOne(+id); } + + @Get('/cuenta/:id_cuenta') + findByCuenta(@Param('id_cuenta') id_cuenta: string) { + return this.bitacoraMesaService.findByCuenta(+id_cuenta); + } } diff --git a/src/bitacora_mesa/bitacora_mesa.service.ts b/src/bitacora_mesa/bitacora_mesa.service.ts index 6513293..c90543c 100644 --- a/src/bitacora_mesa/bitacora_mesa.service.ts +++ b/src/bitacora_mesa/bitacora_mesa.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { BitacoraMesa } from './entities/bitacora_mesa.entity'; @@ -15,10 +15,39 @@ export class BitacoraMesaService { } findAll() { - return this.bitacoraMesaRepository.find({relations:['mesa','alumno_inscrito'],take:100}); + return this.bitacoraMesaRepository.find({ + relations: ['mesa', 'alumno_inscrito'], + take: 100, + }); } findOne(id: number) { return `This action returns a #${id} bitacoraMesa`; } + + async findByCuenta(id_cuenta: number) { + const alumno = await this.bitacoraMesaRepository.findOne({ + where: { + alumno_inscrito: { + alumno: { + id_cuenta: id_cuenta, + }, + }, + }, + relations: { + alumno_inscrito: { + alumno: true, + }, + mesa: true, + }, + order: { + tiempo_entrada: 'DESC', + }, + }); + if (!alumno) { + throw new NotFoundException('alumno sin mesa'); + } + + return alumno; + } }