added Lino
This commit is contained in:
@@ -15,7 +15,7 @@ export class MesaController {
|
||||
async findAllActivo() {
|
||||
return this.mesaService.findAllActivo();
|
||||
}
|
||||
|
||||
|
||||
@Patch(':id')
|
||||
async updateActivo(
|
||||
@Param('id') id: number,
|
||||
|
||||
@@ -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 } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user