added Lino

This commit is contained in:
2026-02-10 13:26:16 -06:00
4 changed files with 66 additions and 10 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ export class MesaController {
async findAllActivo() {
return this.mesaService.findAllActivo();
}
@Patch(':id')
async updateActivo(
@Param('id') id: number,
+31 -1
View File
@@ -9,12 +9,42 @@ export class MesaService {
constructor(
@InjectRepository(Mesa)
private readonly mesaRepository: Repository<Mesa>,
) {}
) { }
async asignarMesa(idUsuario: number, idMesa: number) {
const yaTieneMesa = await this.mesaRepository.findOne({
where: { id_mesa: idMesa }
});
if (yaTieneMesa) {
throw new BadRequestException('El usuario ya tiene una mesa asignada');
}
const mesa = await this.mesaRepository.findOne({
where: { id_mesa: idMesa }
});
if (!mesa) {
throw new NotFoundException('Mesa no existe');
}
mesa.activo = false;
await this.mesaRepository.save(mesa);
return await this.mesaRepository.save({
id_usuario: idUsuario,
id_mesa: idMesa,
});
}
async findAll(): Promise<Mesa[]> {
return await this.mesaRepository.find();
}
async findAllActivo(): Promise<Mesa[]> {
return await this.mesaRepository.find({ where: { activo: true } });
}