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