Files
api-AT/src/mesa/mesa.service.ts
T

33 lines
930 B
TypeScript
Raw Normal View History

2025-09-22 18:09:41 -06:00
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<Mesa>,
) {}
2026-02-05 14:14:44 -05:00
2025-09-22 18:09:41 -06:00
async findAll(): Promise<Mesa[]> {
return await this.mesaRepository.find();
}
2026-01-13 19:12:45 -06:00
async findAllActivo(): Promise<Mesa[]> {
return await this.mesaRepository.find({where:{activo:true}});
}
2025-09-22 18:09:41 -06:00
async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {
2026-01-28 12:51:55 -06:00
const mesa = await this.mesaRepository.findOne({ where: { id_mesa: id } });
2025-09-22 18:09:41 -06:00
if (!mesa) {
throw new NotFoundException(`La mesa no fue encontrada`);
}
mesa.activo = updateMesaDto.activo;
return this.mesaRepository.save(mesa);
}
}