add mesa
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export class CreateMesaDto {}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { IsBoolean, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class UpdateMesaDto {
|
||||
@IsNotEmpty()
|
||||
@IsBoolean()
|
||||
activo: boolean;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Entity, PrimaryColumn, Column } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'mesa' })
|
||||
export class Mesa {
|
||||
@PrimaryColumn({ name: 'id_mesa', type: 'int' })
|
||||
idMesa: number;
|
||||
|
||||
@Column({ name: 'activo', type: 'tinyint', default: 1 })
|
||||
activo: boolean;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Controller, Body, Patch, Param, Delete, Get } from '@nestjs/common';
|
||||
import { MesaService } from './mesa.service';
|
||||
import { UpdateMesaDto } from './dto/update-mesa.dto';
|
||||
|
||||
@Controller('mesa')
|
||||
export class MesaController {
|
||||
constructor(private readonly mesaService: MesaService) {}
|
||||
|
||||
@Get('all')
|
||||
async findAll() {
|
||||
return this.mesaService.findAll();
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async updateActivo(
|
||||
@Param('id') id: number,
|
||||
@Body() updateMesaDto: UpdateMesaDto,
|
||||
) {
|
||||
return this.mesaService.updateActivo(id, updateMesaDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MesaService } from './mesa.service';
|
||||
import { MesaController } from './mesa.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Mesa } from './entities/mesa.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Mesa])],
|
||||
controllers: [MesaController],
|
||||
providers: [MesaService],
|
||||
})
|
||||
export class MesaModule {}
|
||||
@@ -0,0 +1,27 @@
|
||||
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>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find();
|
||||
}
|
||||
|
||||
async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {
|
||||
const mesa = await this.mesaRepository.findOne({ where: { idMesa: id } });
|
||||
if (!mesa) {
|
||||
throw new NotFoundException(`La mesa no fue encontrada`);
|
||||
}
|
||||
|
||||
mesa.activo = updateMesaDto.activo;
|
||||
return this.mesaRepository.save(mesa);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user