update and create equipo
This commit is contained in:
@@ -1 +1,27 @@
|
||||
export class CreateEquipoDto {}
|
||||
import { IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateEquipoDto {
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_area_ubicacion: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_equipo: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_plataforma: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
ip: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre_equipo: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
ubicacion: string;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
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';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
@@ -27,8 +28,18 @@ export class EquipoController {
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number): Promise<Equipo> {
|
||||
return this.equipoService.findOne(+id);
|
||||
findOne(@Param('id') id: string): Promise<Equipo> {
|
||||
return this.equipoService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.create(equipo);
|
||||
}
|
||||
|
||||
@Patch()
|
||||
update(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.update(equipo);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
import { AlumnoInscritoService } from 'src/alumno_inscrito/alumno_inscrito.service';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EquipoService {
|
||||
@@ -47,6 +51,7 @@ export class EquipoService {
|
||||
.orderBy('equipo.ubicacion', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
findDisable() {
|
||||
return this.equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
@@ -57,9 +62,9 @@ export class EquipoService {
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async findOne(id_equipo: number): Promise<Equipo> {
|
||||
async findOne(ubicacion: string): Promise<Equipo> {
|
||||
const equipo = await this.equipoRepository.findOne({
|
||||
where: { id_equipo },
|
||||
where: { ubicacion },
|
||||
});
|
||||
if (!equipo) {
|
||||
throw new NotFoundException('not found');
|
||||
@@ -110,5 +115,22 @@ export class EquipoService {
|
||||
|
||||
return equipos;
|
||||
}
|
||||
|
||||
async create(equipo: CreateEquipoDto) {
|
||||
const find = await this.equipoRepository.findOne({
|
||||
where: { ubicacion: equipo.ubicacion },
|
||||
});
|
||||
|
||||
if (find) {
|
||||
throw new BadRequestException('Ubicacion ya existente');
|
||||
}
|
||||
|
||||
const create = await this.equipoRepository.create(equipo);
|
||||
return this.equipoRepository.save(create);
|
||||
}
|
||||
|
||||
async update(equipo: CreateEquipoDto) {
|
||||
return this.equipoRepository.update(equipo.id_equipo, equipo);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user