Merge branch 'Lino' into Dev
This commit is contained in:
+5
-1
@@ -20,6 +20,8 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
import { OperationsModule } from './Operations/operations.module';
|
||||
import { Recibo } from './recibo/entities/recibo.entity';
|
||||
import { ReciboModule } from './recibo/recibo.module';
|
||||
import { MesaModule } from './mesa/mesa.module';
|
||||
import { Mesa } from './mesa/entities/mesa.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -47,6 +49,7 @@ import { ReciboModule } from './recibo/recibo.module';
|
||||
Sancion,
|
||||
Carrera,
|
||||
Recibo,
|
||||
Mesa,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -60,9 +63,10 @@ import { ReciboModule } from './recibo/recibo.module';
|
||||
AlumnoSancionModule,
|
||||
OperationsModule,
|
||||
ReciboModule,
|
||||
MesaModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -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