From c7747af37d9c3eeb41a5190b6c83923d275f6d8e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 21:25:15 -0500 Subject: [PATCH] Avances pero hay algunos errores --- .../carrera-programa.controller.ts | 2 +- src/carrito/carrito.service.ts | 1 + src/carrito/dto/carrito-create.dto.ts | 4 +-- src/equipo/equipo.service.ts | 10 +----- .../dto/hora-excepcion-create.dto.ts | 6 ++++ .../hora-excepcion.controller.ts | 14 +++++--- src/hora-excepcion/hora-excepcion.service.ts | 35 ++++++++++++++++++- 7 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 src/hora-excepcion/dto/hora-excepcion-create.dto.ts diff --git a/src/carrera-programa/carrera-programa.controller.ts b/src/carrera-programa/carrera-programa.controller.ts index f7a27b5..ee0f11e 100644 --- a/src/carrera-programa/carrera-programa.controller.ts +++ b/src/carrera-programa/carrera-programa.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'; import { CarreraProgramaService } from './carrera-programa.service'; import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto'; import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto'; diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index 7fa8a77..18d3e3f 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -78,6 +78,7 @@ export class CarritoService { if (modulo) busqueda.modulo = modulo; if (institucionTipoCarrito) busqueda.institucionTipoCarrito = institucionTipoCarrito; //falta página + return this.repository.find(busqueda); } diff --git a/src/carrito/dto/carrito-create.dto.ts b/src/carrito/dto/carrito-create.dto.ts index 143e0f6..e75ce49 100644 --- a/src/carrito/dto/carrito-create.dto.ts +++ b/src/carrito/dto/carrito-create.dto.ts @@ -1,4 +1,4 @@ -import { IsNumber } from 'class-validator'; +import { IsNumber, IsString } from 'class-validator'; export class CarritoCreateDto { @IsNumber() @@ -8,6 +8,6 @@ export class CarritoCreateDto { id_modulo: number; // Cambiar por IsString - @IsNumber() + @IsString() carrito: string; } diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index 9f1e53e..a71bb25 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -9,15 +9,7 @@ export class EquipoService { @InjectRepository(Equipo) private repository: Repository, ) {} - async create( - equipo: string, - numero_inventario: string, - numero_serie: string, - prestado: boolean, - id_carrito: number, - id_programa: number, - id_status: number, - ) {} + async create() {} findAll() { return this.repository.find(); diff --git a/src/hora-excepcion/dto/hora-excepcion-create.dto.ts b/src/hora-excepcion/dto/hora-excepcion-create.dto.ts new file mode 100644 index 0000000..2208fb9 --- /dev/null +++ b/src/hora-excepcion/dto/hora-excepcion-create.dto.ts @@ -0,0 +1,6 @@ +import { IsInt } from 'class-validator'; + +export class HoraExcepcionDto { + @IsInt() + id_institucion: number; +} diff --git a/src/hora-excepcion/hora-excepcion.controller.ts b/src/hora-excepcion/hora-excepcion.controller.ts index 8f1fe44..7e93a4d 100644 --- a/src/hora-excepcion/hora-excepcion.controller.ts +++ b/src/hora-excepcion/hora-excepcion.controller.ts @@ -1,15 +1,21 @@ -import { Controller, Delete, Get, Post, Put } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Post, Put, Param } from '@nestjs/common'; import { HoraExcepcionService } from './hora-excepcion.service'; +import { HoraExcepcionDto } from './dto/hora-excepcion-create.dto' + @Controller('hora-excepcion') export class HoraExcepcionController { constructor(private horaExcepcionService: HoraExcepcionService) {} @Post() - create() {} + create(@Body() body: HoraExcepcionDto) { + return this.horaExcepcionService.create(body.id_institucion) + } - @Delete() - delete() {} + @Delete(':id') + delete(@Param('id') id_hora_excepcion: number) { + return this.horaExcepcionService.delete(id_hora_excepcion) + } @Get() get() {} diff --git a/src/hora-excepcion/hora-excepcion.service.ts b/src/hora-excepcion/hora-excepcion.service.ts index d4de4a0..e639d8b 100644 --- a/src/hora-excepcion/hora-excepcion.service.ts +++ b/src/hora-excepcion/hora-excepcion.service.ts @@ -1,12 +1,45 @@ -import { Injectable } from '@nestjs/common'; +import { ConflictException, NotFoundException, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { HoraExcepcion } from './entity/hora-excepcion.entity'; +import { InstitucionService } from '../institucion/institucion.service'; + @Injectable() export class HoraExcepcionService { constructor( @InjectRepository(HoraExcepcion) private repository: Repository, + private institucionService: InstitucionService ) {} + + async create(id_institucion: number) { + const institucion = await this.institucionService.findById(id_institucion) + const nuevaHoraExcepcion = this.repository.create({institucion}); + + return this.repository + .findOne({institucion}) + .then((existeHoraExcepcion) => { + if (existeHoraExcepcion) throw new ConflictException('Ya existe esta hora excepción') + return this.repository.save(nuevaHoraExcepcion) + }) + .then(() => ({message: 'Se creo correctamente la hora excepción'})) + } + + findById(id_hora_excepcion: number) { + return this.repository + .findOne({ id_hora_excepcion }) + .then((horaExcepcion) => { + if (!horaExcepcion) + throw new NotFoundException('No existe esta carrera-programa'); + return horaExcepcion; + }); + } + + delete(id_hora_excepcion: number) { + this.findById(id_hora_excepcion) + .then(() => { + return this.repository.delete(id_hora_excepcion) + }) + } }