import { Injectable, NotFoundException } from '@nestjs/common'; import { UpdateMesaDto } from './dto/update-mesa.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Mesa } from './entities/mesa.entity'; @Injectable() export class MesaService { constructor( @InjectRepository(Mesa) private readonly mesaRepository: Repository, ) {} async findAll(): Promise { return await this.mesaRepository.find(); } async findAllActivo(): Promise { return await this.mesaRepository.find({where:{activo:true}}); } async updateActivo(id: number, updateMesaDto: UpdateMesaDto) { const mesa = await this.mesaRepository.findOne({ where: { id_mesa: id } }); if (!mesa) { throw new NotFoundException(`La mesa no fue encontrada`); } mesa.activo = updateMesaDto.activo; return this.mesaRepository.save(mesa); } }