diff --git a/src/equipo/dto/create-equipo.dto.ts b/src/equipo/dto/create-equipo.dto.ts index 93601d1..1548e88 100644 --- a/src/equipo/dto/create-equipo.dto.ts +++ b/src/equipo/dto/create-equipo.dto.ts @@ -1,27 +1,35 @@ -import { IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; +import { IsBoolean, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; export class CreateEquipoDto { -@IsInt() -@IsNotEmpty() -id_area_ubicacion: number; + @IsInt() + @IsNotEmpty() + id_area_ubicacion: number; -@IsInt() -@IsOptional() -id_equipo: number; + @IsInt() + @IsOptional() + id_equipo: number; -@IsInt() -@IsNotEmpty() -id_plataforma: number; + @IsInt() + @IsNotEmpty() + id_plataforma: number; -@IsString() -@IsOptional() -ip: string; + @IsString() + @IsOptional() + ip: string; -@IsString() -@IsNotEmpty() -nombre_equipo: string; + @IsString() + @IsNotEmpty() + nombre_equipo: string; -@IsString() -@IsNotEmpty() -ubicacion: string; + @IsString() + @IsNotEmpty() + ubicacion: string; +} + +export class UpdateAreaEquiposDto { + @IsInt() + id_area_ubicacion: number; + + @IsBoolean() + activo: boolean; } diff --git a/src/equipo/equipo.controller.ts b/src/equipo/equipo.controller.ts index 6fd3d0c..febf7f0 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; import { EquipoService } from './equipo.service'; import { Equipo } from './entities/equipo.entity'; -import { CreateEquipoDto } from './dto/create-equipo.dto'; +import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto'; @Controller('equipo') export class EquipoController { @@ -51,5 +51,18 @@ export class EquipoController { toggleActivo(@Param('id') id: number) { return this.equipoService.toggleActivo(+id); } + + @Patch('actualizar-area') + actualizarPorArea( + @Body() updateAreaEquiposDto: UpdateAreaEquiposDto, + ) { + const { id_area_ubicacion, activo } = updateAreaEquiposDto; + + return this.equipoService.actualizarEquiposPorArea( + id_area_ubicacion, + activo, + ); + } + } //IO diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index 364651b..d6daa9f 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -204,5 +204,21 @@ export class EquipoService { activo: nuevoActivo, }; } + + async actualizarEquiposPorArea( + id_area_ubicacion: number, + activo: boolean, + ) { + const result = await this.equipoRepository.update( + { id_area_ubicacion }, + { activo }, + ); + + return { + message: 'Equipos actualizados correctamente', + affected: result.affected, + }; + } + } //IO