From 0bf224d1d27ff2d831411e70e75165afdee2acd2 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 18:38:31 -0500 Subject: [PATCH 01/10] carrera --- src/carrera/carrera.controller.ts | 11 +++++------ src/carrera/carrera.service.ts | 11 ++++++++--- src/carrera/dto/carrera-get-dto.ts | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/carrera/carrera.controller.ts b/src/carrera/carrera.controller.ts index 1d11cf8..436f540 100644 --- a/src/carrera/carrera.controller.ts +++ b/src/carrera/carrera.controller.ts @@ -6,14 +6,13 @@ import { CarritoGetDto } from './dto/carrera-get-dto'; export class CarreraController { constructor(private carreraService: CarreraService) {} - @Get() - get() { - // recibir id_institucion y traer todoas las carreras de esa institiucion - return this.carreraService.findAll(); - } - @Get('carreras') carreras(@Query() query: CarritoGetDto) { + return this.carreraService.findAllByIdInstitucion(Number(query.id_institucion)); + } + + @Get('carrera') + carrera(@Query() query: CarritoGetDto) { return this.carreraService.findById(Number(query.id_carrera)); } } diff --git a/src/carrera/carrera.service.ts b/src/carrera/carrera.service.ts index 7d36466..fd19233 100644 --- a/src/carrera/carrera.service.ts +++ b/src/carrera/carrera.service.ts @@ -2,15 +2,20 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Carrera } from './entity/carrera.entity'; +import { InstitucionService } from '../institucion/institucion.service'; +import { Institucion } from 'src/institucion/entity/institucion.entity'; @Injectable() export class CarreraService { constructor( @InjectRepository(Carrera) private repository: Repository, - ) {} + private institucionService: InstitucionService, + ) { } - findAll() { - return this.repository.find(); + findAllByIdInstitucion(id_institucion: number) { + return this.institucionService + .findById(id_institucion) + .then((institucion) => this.repository.find({institucion})) } findById(id_carrera: number) { diff --git a/src/carrera/dto/carrera-get-dto.ts b/src/carrera/dto/carrera-get-dto.ts index 9af779b..9b84077 100644 --- a/src/carrera/dto/carrera-get-dto.ts +++ b/src/carrera/dto/carrera-get-dto.ts @@ -4,4 +4,7 @@ export class CarritoGetDto { // Cambiar IsString por IsNumberString @IsString() id_carrera: string; + + @IsString() + id_institucion: String; } From 2a6d0c6219c7a8b28c7c1a8dfb69abb77881f1ad Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 19:09:22 -0500 Subject: [PATCH 02/10] carrera-programa --- .../carrera-programa.controller.ts | 13 ++++------- .../carrera-programa.service.ts | 23 ++++++------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/carrera-programa/carrera-programa.controller.ts b/src/carrera-programa/carrera-programa.controller.ts index 1c25597..f7a27b5 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, Post, Put } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post, Put } 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'; @@ -16,16 +16,13 @@ export class CarreraProgramaController { } // terminar delte - @Delete() - delete() {} + @Delete(':id') + delete(@Param('id') id_carrera_programa: number) { + return this.carreraProgramaService.delete(id_carrera_programa) + } @Get() get() { return this.carreraProgramaService.findAll(); } - - @Put() - update(@Body() body: CarreraProgramaUpdateDto) { - return this.carreraProgramaService.update(body); - } } diff --git a/src/carrera-programa/carrera-programa.service.ts b/src/carrera-programa/carrera-programa.service.ts index 5680a6e..7dd9b3e 100644 --- a/src/carrera-programa/carrera-programa.service.ts +++ b/src/carrera-programa/carrera-programa.service.ts @@ -47,25 +47,16 @@ export class CarreraProgramaService { .findOne({ id_carrera_programa }) .then((carreraPrograma) => { if (!carreraPrograma) - throw new NotFoundException('No existe esta carrera programa'); + throw new NotFoundException('No existe esta carrera-programa'); return carreraPrograma; }); } - // Eliminar update, no tiene sentido tenerlo, me equivoque xd - async update(attrs: Partial) { - const carreraPrograma = await this.findById(attrs.id_carrera_programa); - - return this.repository - .findOne({ id_carrera_programa: attrs.id_carrera_programa }) - .then((existeCarreraPrograma) => { - if (existeCarreraPrograma) - throw new ConflictException('Ya existe esta carrera programa'); - Object.assign(carreraPrograma, attrs); - return this.repository.save(carreraPrograma); - }) - .then(() => ({ - message: 'Se actualizo correctamente la carrera programa', - })); + //No estoy seguro de que esto este bien :) + delete(id_carrera_programa: number) { + this.findById(id_carrera_programa) + .then(() => { + return this.repository.delete(id_carrera_programa) + }) } } From 6d6463742349ba606570edcc79858344bb497ff9 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 20:46:09 -0500 Subject: [PATCH 03/10] carrito incompleto --- src/carrito/carrito.controller.ts | 14 +++------- src/carrito/carrito.service.ts | 44 ++++++++++++++++++++---------- src/carrito/dto/carrito-get-dto.ts | 20 ++++++++++++++ src/carrito/dto/carrito.dto.ts | 6 ++++ src/carrito/dto/carrtio-get-dto.ts | 22 --------------- 5 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 src/carrito/dto/carrito-get-dto.ts create mode 100644 src/carrito/dto/carrito.dto.ts delete mode 100644 src/carrito/dto/carrtio-get-dto.ts diff --git a/src/carrito/carrito.controller.ts b/src/carrito/carrito.controller.ts index 6adb113..6130ef3 100644 --- a/src/carrito/carrito.controller.ts +++ b/src/carrito/carrito.controller.ts @@ -2,7 +2,8 @@ import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; import { CarritoService } from './carrito.service'; import { CarritoCreateDto } from './dto/carrito-create.dto'; import { CarritoUpdateDto } from './dto/carrito-update.dto'; -import { CarritoGetDto } from './dto/carrtio-get-dto'; +import { CarritoGetDto } from './dto/carrito-get-dto'; +import { CarritoDto } from './dto/carrito.dto' @Controller('carrito') export class CarritoController { @@ -13,7 +14,6 @@ export class CarritoController { return this.carritoService.create( body.id_tipo_carrito, body.id_modulo, - body.carrito, ); } @@ -22,20 +22,14 @@ export class CarritoController { return this.carritoService.findAll(); } - // Crear dto que solo espere el campo id_carrito @Get('carrito') - carrito(@Query() query: CarritoGetDto) { + carrito(@Query() query: CarritoDto) { return this.carritoService.findById(Number(query.id_carrito)); } @Get('carritos') carritos(@Query() query: CarritoGetDto) { - return this.carritoService.findByIdModulo( - Number(query.pagina), - Number(query.id_modulo), - Number(query.id_tipo_carrito), - query.activo === 'true', - ); + return this.carritoService.findByIdModulo(query); } @Get('carritoInstitucion') diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index 16d24a6..7fa8a77 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -3,9 +3,11 @@ import { Injectable, NotFoundException, } from '@nestjs/common'; -import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; import { Carrito } from './entity/carrito.entity'; +import { Modulo } from '../modulo/entity/modulo.entity'; +import { InstitucionTipoCarrito } from '../institucion-tipo-carrito/entity/institucion-tipo-carrito.entity'; import { ModuloService } from '../modulo/modulo.service'; import { InstitucionTipoCarritoService } from '../institucion-tipo-carrito/institucion-tipo-carrito.service'; @@ -18,20 +20,19 @@ export class CarritoService { ) {} // Eliminar carrito (argumento) de este proceso. Buscar cuantos carritos tiene el modulo de ese tipo carrito y automaticamente generar carrito - async create(id_tipo_carrito: number, id_modulo: number, carrito: string) { + async create(id_tipo_carrito: number, id_modulo: number) { const modulo = await this.moduloService.findById(id_modulo); const tipoCarrito = await this.institucionTipoCarritoService.findByIdTipoCarito( id_tipo_carrito, ); const nuevoCarrito = this.repository.create({ - carrito, modulo, tipoCarrito, }); return this.repository - .findOne({ carrito, modulo, tipoCarrito }) + .findOne({ modulo, tipoCarrito }) .then((existeCarrito) => { if (existeCarrito) throw new ConflictException('Este carrito ya existe en este modulo'); @@ -54,17 +55,30 @@ export class CarritoService { } // Toma de ejemplo la funcion que esta en /src/usuario/usuario.service.ts - findByIdModulo( - pagina: number, - id_modulo: number, - id_tipo_carrito: number, - activo: boolean, - ) { - return this.repository.findOne(id_modulo).then((modulo) => { - if (!modulo) - throw new NotFoundException('No existen carritos es este modulo'); - return modulo; - }); + async findByIdModulo(filtros: { + pagina?: string, + id_modulo?: string, + id_tipo_carrito?: string, + activo?: string, + }) { + const busqueda: { + modulo?: Modulo; + institucionTipoCarrito?: InstitucionTipoCarrito; + activo?: string; + } = {} + + const modulo = filtros.id_modulo + ? await this.moduloService.findById(Number(filtros.id_modulo)) + : null; + const institucionTipoCarrito = filtros.id_tipo_carrito + ? await this.institucionTipoCarritoService.findById(Number(filtros.id_tipo_carrito)) + : null + + if (filtros.activo) busqueda.activo = filtros.activo; + if (modulo) busqueda.modulo = modulo; + if (institucionTipoCarrito) busqueda.institucionTipoCarrito = institucionTipoCarrito; + //falta página + return this.repository.find(busqueda); } // re hacer diff --git a/src/carrito/dto/carrito-get-dto.ts b/src/carrito/dto/carrito-get-dto.ts new file mode 100644 index 0000000..cc6a178 --- /dev/null +++ b/src/carrito/dto/carrito-get-dto.ts @@ -0,0 +1,20 @@ +import { IsBooleanString, IsNumberString, IsOptional } from 'class-validator'; + +export class CarritoGetDto { + @IsNumberString() + pagina: string; + + @IsNumberString() + @IsOptional() + id_carrito?: string; + + @IsNumberString() + id_tipo_carrito: string; + + @IsNumberString() + id_modulo: string; + + @IsBooleanString() + @IsOptional() + activo?: string; +} diff --git a/src/carrito/dto/carrito.dto.ts b/src/carrito/dto/carrito.dto.ts new file mode 100644 index 0000000..721db81 --- /dev/null +++ b/src/carrito/dto/carrito.dto.ts @@ -0,0 +1,6 @@ +import { IsNumberString, } from 'class-validator'; + +export class CarritoDto { + @IsNumberString() + id_carrito: string; +} diff --git a/src/carrito/dto/carrtio-get-dto.ts b/src/carrito/dto/carrtio-get-dto.ts deleted file mode 100644 index bc3f71b..0000000 --- a/src/carrito/dto/carrtio-get-dto.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IsOptional, IsString } from 'class-validator'; - -export class CarritoGetDto { - // Cambiar por IsNumberString, en todas - @IsString() - pagina: string; - - // De aqui para abajo agregar IsOptional y operadro ? - @IsString() - id_carrito: string; - - @IsString() - id_tipo_carrito: string; - - @IsString() - id_modulo: string; - - // Cambiat por IsBooleanString - @IsString() - @IsOptional() - activo?: string; -} From c7747af37d9c3eeb41a5190b6c83923d275f6d8e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 21:25:15 -0500 Subject: [PATCH 04/10] 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) + }) + } } From b337861c6c187e62fc9721fcb7972e02c41a6931 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Mon, 25 Apr 2022 17:46:16 -0500 Subject: [PATCH 05/10] hora-excepcion listo --- .../dto/hora-excepcion-create.dto.ts | 2 +- src/hora-excepcion/hora-excepcion.controller.ts | 2 +- src/hora-excepcion/hora-excepcion.service.ts | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/hora-excepcion/dto/hora-excepcion-create.dto.ts b/src/hora-excepcion/dto/hora-excepcion-create.dto.ts index 2208fb9..e3fff5b 100644 --- a/src/hora-excepcion/dto/hora-excepcion-create.dto.ts +++ b/src/hora-excepcion/dto/hora-excepcion-create.dto.ts @@ -2,5 +2,5 @@ import { IsInt } from 'class-validator'; export class HoraExcepcionDto { @IsInt() - id_institucion: number; + id_institucion_dia: number; } diff --git a/src/hora-excepcion/hora-excepcion.controller.ts b/src/hora-excepcion/hora-excepcion.controller.ts index 7e93a4d..67d4eab 100644 --- a/src/hora-excepcion/hora-excepcion.controller.ts +++ b/src/hora-excepcion/hora-excepcion.controller.ts @@ -9,7 +9,7 @@ export class HoraExcepcionController { @Post() create(@Body() body: HoraExcepcionDto) { - return this.horaExcepcionService.create(body.id_institucion) + return this.horaExcepcionService.create(body.id_institucion_dia) } @Delete(':id') diff --git a/src/hora-excepcion/hora-excepcion.service.ts b/src/hora-excepcion/hora-excepcion.service.ts index e639d8b..a777570 100644 --- a/src/hora-excepcion/hora-excepcion.service.ts +++ b/src/hora-excepcion/hora-excepcion.service.ts @@ -2,23 +2,22 @@ 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'; - +import { InstitucionDiaService } from '../institucion-dia/institucion-dia.service' @Injectable() export class HoraExcepcionService { constructor( @InjectRepository(HoraExcepcion) private repository: Repository, - private institucionService: InstitucionService - ) {} + private institucionDiaService: InstitucionDiaService, + ) { } - async create(id_institucion: number) { - const institucion = await this.institucionService.findById(id_institucion) - const nuevaHoraExcepcion = this.repository.create({institucion}); + async create(id_institucion_dia: number) { + const institucionDia = await this.institucionDiaService.findById(id_institucion_dia) + const nuevaHoraExcepcion = this.repository.create({institucionDia}); return this.repository - .findOne({institucion}) + .findOne({institucionDia}) .then((existeHoraExcepcion) => { if (existeHoraExcepcion) throw new ConflictException('Ya existe esta hora excepción') return this.repository.save(nuevaHoraExcepcion) From 2042135d9e0a2002f95406c8ad97ef084b55d517 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Mon, 25 Apr 2022 17:56:10 -0500 Subject: [PATCH 06/10] Errores del carrito --- src/carrera-programa/carrera-programa.controller.ts | 1 - src/carrito/carrito.service.ts | 4 ++-- src/carrito/dto/carrito-get-dto.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/carrera-programa/carrera-programa.controller.ts b/src/carrera-programa/carrera-programa.controller.ts index ee0f11e..0b5dc24 100644 --- a/src/carrera-programa/carrera-programa.controller.ts +++ b/src/carrera-programa/carrera-programa.controller.ts @@ -15,7 +15,6 @@ export class CarreraProgramaController { ); } - // terminar delte @Delete(':id') delete(@Param('id') id_carrera_programa: number) { return this.carreraProgramaService.delete(id_carrera_programa) diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index 18d3e3f..b1ad50e 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -59,12 +59,12 @@ export class CarritoService { pagina?: string, id_modulo?: string, id_tipo_carrito?: string, - activo?: string, + activo?: boolean, }) { const busqueda: { modulo?: Modulo; institucionTipoCarrito?: InstitucionTipoCarrito; - activo?: string; + activo?: boolean; } = {} const modulo = filtros.id_modulo diff --git a/src/carrito/dto/carrito-get-dto.ts b/src/carrito/dto/carrito-get-dto.ts index cc6a178..942eddb 100644 --- a/src/carrito/dto/carrito-get-dto.ts +++ b/src/carrito/dto/carrito-get-dto.ts @@ -16,5 +16,5 @@ export class CarritoGetDto { @IsBooleanString() @IsOptional() - activo?: string; + activo?: boolean; } From 94b411d549d07b4e5d1a857d78ab176d0666343d Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sat, 30 Apr 2022 16:23:49 -0500 Subject: [PATCH 07/10] Error de los modules --- src/carrera/carrera.module.ts | 3 ++- src/carrera/carrera.service.ts | 17 +++++++++-------- src/carrito/carrito.service.ts | 4 ++++ src/hora-excepcion/hora-excepcion.module.ts | 4 +++- src/hora-excepcion/hora-excepcion.service.ts | 3 +-- src/institucion-dia/institucion-dia.module.ts | 1 + 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/carrera/carrera.module.ts b/src/carrera/carrera.module.ts index 5707bd3..e57e605 100644 --- a/src/carrera/carrera.module.ts +++ b/src/carrera/carrera.module.ts @@ -3,9 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { CarreraController } from './carrera.controller'; import { CarreraService } from './carrera.service'; import { Carrera } from './entity/carrera.entity'; +import { InstitucionModule } from '../institucion/institucion.module'; @Module({ - imports: [TypeOrmModule.forFeature([Carrera])], + imports: [TypeOrmModule.forFeature([Carrera]), InstitucionModule], controllers: [CarreraController], providers: [CarreraService], exports: [CarreraService], diff --git a/src/carrera/carrera.service.ts b/src/carrera/carrera.service.ts index fd19233..573172a 100644 --- a/src/carrera/carrera.service.ts +++ b/src/carrera/carrera.service.ts @@ -3,20 +3,13 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Carrera } from './entity/carrera.entity'; import { InstitucionService } from '../institucion/institucion.service'; -import { Institucion } from 'src/institucion/entity/institucion.entity'; @Injectable() export class CarreraService { constructor( @InjectRepository(Carrera) private repository: Repository, private institucionService: InstitucionService, - ) { } - - findAllByIdInstitucion(id_institucion: number) { - return this.institucionService - .findById(id_institucion) - .then((institucion) => this.repository.find({institucion})) - } + ) {} findById(id_carrera: number) { return this.repository.findOne({ id_carrera }).then((carrera) => { @@ -24,4 +17,12 @@ export class CarreraService { return carrera; }); } + + findAllByIdInstitucion(id_institucion: number) { + return this.institucionService + .findById(id_institucion) + .then((institucion) => this.repository.find({institucion})) + } + + } diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index b1ad50e..86d7a62 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -26,6 +26,10 @@ export class CarritoService { await this.institucionTipoCarritoService.findByIdTipoCarito( id_tipo_carrito, ); + const carrito = this.repository.findAndCount({ modulo, tipoCarrito }) + .then((existeCarrito) => { + console.log(existeCarrito) + }) const nuevoCarrito = this.repository.create({ modulo, tipoCarrito, diff --git a/src/hora-excepcion/hora-excepcion.module.ts b/src/hora-excepcion/hora-excepcion.module.ts index a69ad94..c751451 100644 --- a/src/hora-excepcion/hora-excepcion.module.ts +++ b/src/hora-excepcion/hora-excepcion.module.ts @@ -3,10 +3,12 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { HoraExcepcionController } from './hora-excepcion.controller'; import { HoraExcepcionService } from './hora-excepcion.service'; import { HoraExcepcion } from './entity/hora-excepcion.entity'; +import { InstitucionDiaModule } from '../institucion-dia/institucion-dia.module' @Module({ - imports: [TypeOrmModule.forFeature([HoraExcepcion])], + imports: [TypeOrmModule.forFeature([HoraExcepcion]), InstitucionDiaModule], controllers: [HoraExcepcionController], providers: [HoraExcepcionService], + exports: [HoraExcepcionService] }) export class HoraExcepcionModule {} diff --git a/src/hora-excepcion/hora-excepcion.service.ts b/src/hora-excepcion/hora-excepcion.service.ts index a777570..6d7114c 100644 --- a/src/hora-excepcion/hora-excepcion.service.ts +++ b/src/hora-excepcion/hora-excepcion.service.ts @@ -7,8 +7,7 @@ import { InstitucionDiaService } from '../institucion-dia/institucion-dia.servic @Injectable() export class HoraExcepcionService { constructor( - @InjectRepository(HoraExcepcion) - private repository: Repository, + @InjectRepository(HoraExcepcion) private repository: Repository, private institucionDiaService: InstitucionDiaService, ) { } diff --git a/src/institucion-dia/institucion-dia.module.ts b/src/institucion-dia/institucion-dia.module.ts index 88c0e88..ac3c1e6 100644 --- a/src/institucion-dia/institucion-dia.module.ts +++ b/src/institucion-dia/institucion-dia.module.ts @@ -10,5 +10,6 @@ import { InstitucionModule } from '../institucion/institucion.module'; imports: [TypeOrmModule.forFeature([Dia, InstitucionDia]), InstitucionModule], controllers: [InstitucionDiaController], providers: [InstitucionDiaService], + exports: [InstitucionDiaService] }) export class InstitucionDiaModule {} From c7a6f6aaebd4e3ceca372023b62fec2819b46367 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sat, 30 Apr 2022 19:56:04 -0500 Subject: [PATCH 08/10] contamos carrito automaticamente --- src/carrito/carrito.service.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index 86d7a62..e58ca42 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -19,24 +19,26 @@ export class CarritoService { private institucionTipoCarritoService: InstitucionTipoCarritoService, ) {} - // Eliminar carrito (argumento) de este proceso. Buscar cuantos carritos tiene el modulo de ese tipo carrito y automaticamente generar carrito async create(id_tipo_carrito: number, id_modulo: number) { const modulo = await this.moduloService.findById(id_modulo); const tipoCarrito = await this.institucionTipoCarritoService.findByIdTipoCarito( id_tipo_carrito, ); - const carrito = this.repository.findAndCount({ modulo, tipoCarrito }) - .then((existeCarrito) => { - console.log(existeCarrito) - }) + let carrito = "" + await this.repository.findAndCount({ modulo, tipoCarrito }) + .then((carritos) => { + carrito = `C0${carritos[1] + 1}` + }) + const nuevoCarrito = this.repository.create({ - modulo, tipoCarrito, + modulo, + carrito, }); return this.repository - .findOne({ modulo, tipoCarrito }) + .findOne({ modulo, tipoCarrito, carrito }) .then((existeCarrito) => { if (existeCarrito) throw new ConflictException('Este carrito ya existe en este modulo'); From 3eab1c937b60f2a40a82d21d49612445f8957450 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sat, 30 Apr 2022 21:18:19 -0500 Subject: [PATCH 09/10] tags de swagger --- catalogos.sql | 1 - package-lock.json | 94 +++++++++++++++++++ package.json | 2 + src/auth/auth.controller.ts | 2 + .../carrera-programa.controller.ts | 2 + src/carrera/carrera.controller.ts | 2 + src/carrito/carrito.controller.ts | 2 + src/equipo/equipo.controller.ts | 2 + .../hora-excepcion.controller.ts | 3 +- .../institucion-dia.controller.ts | 2 + .../institucion-infraccion.controller.ts | 2 + .../institucion-tipo-carrito.controller.ts | 2 + src/institucion/institucion.controller.ts | 3 + src/main.ts | 10 ++ src/modulo/modulo.controller.ts | 3 + src/motivo/motivo.controller.ts | 3 + src/multa/multa.controller.ts | 2 + src/operador/operador.controller.ts | 3 + src/prestamo/prestamo.controller.ts | 2 + src/programa/programa.controller.ts | 2 + src/status/status.controller.ts | 3 + src/tipo-entrada/tipo-entrada.controller.ts | 2 + src/tipo-usuario/tipo-usuario.controller.ts | 3 + src/upload-file/upload-file.controller.ts | 2 + src/usuario/usuario.controller.ts | 3 + 25 files changed, 155 insertions(+), 2 deletions(-) diff --git a/catalogos.sql b/catalogos.sql index 97139de..1782018 100644 --- a/catalogos.sql +++ b/catalogos.sql @@ -37,4 +37,3 @@ INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 2); INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 3); INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 4); INSERT INTO institucion_dia (id_institucion, id_dia) VALUES (2, 5); - diff --git a/package-lock.json b/package-lock.json index 792ebbd..f1c54fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@nestjs/passport": "^8.2.1", "@nestjs/platform-express": "^8.0.0", "@nestjs/schedule": "^1.1.0", + "@nestjs/swagger": "^5.2.1", "@nestjs/typeorm": "^8.0.3", "bcrypt": "^5.0.1", "class-transformer": "^0.5.1", @@ -28,6 +29,7 @@ "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0", + "swagger-ui-express": "^4.3.0", "typeorm": "^0.2.45" }, "devDependencies": { @@ -1510,6 +1512,25 @@ "@nestjs/common": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/@nestjs/mapped-types": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-1.0.1.tgz", + "integrity": "sha512-NFvofzSinp00j5rzUd4tf+xi9od6383iY0JP7o0Bnu1fuItAUkWBgc4EKuIQ3D+c2QI3i9pG1kDWAeY27EMGtg==", + "peerDependencies": { + "@nestjs/common": "^7.0.8 || ^8.0.0", + "class-transformer": "^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0", + "class-validator": "^0.11.1 || ^0.12.0 || ^0.13.0", + "reflect-metadata": "^0.1.12" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, "node_modules/@nestjs/passport": { "version": "8.2.1", "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-8.2.1.tgz", @@ -1632,6 +1653,31 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, + "node_modules/@nestjs/swagger": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-5.2.1.tgz", + "integrity": "sha512-7dNa08WCnTsW/oAk3Ujde+z64JMfNm19DhpXasFR8oJp/9pggYAbYU927HpA+GJsSFJX6adjIRZsCKUqaGWznw==", + "dependencies": { + "@nestjs/mapped-types": "1.0.1", + "lodash": "4.17.21", + "path-to-regexp": "3.2.0" + }, + "peerDependencies": { + "@nestjs/common": "^8.0.0", + "@nestjs/core": "^8.0.0", + "fastify-swagger": "*", + "reflect-metadata": "^0.1.12", + "swagger-ui-express": "*" + }, + "peerDependenciesMeta": { + "fastify-swagger": { + "optional": true + }, + "swagger-ui-express": { + "optional": true + } + } + }, "node_modules/@nestjs/testing": { "version": "8.4.3", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.3.tgz", @@ -8455,6 +8501,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swagger-ui-dist": { + "version": "4.10.3", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.10.3.tgz", + "integrity": "sha512-eR4vsd7sYo0Sx7ZKRP5Z04yij7JkNmIlUQfrDQgC+xO5ABYx+waabzN+nDsQTLAJ4Z04bjkRd8xqkJtbxr3G7w==" + }, + "node_modules/swagger-ui-express": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.3.0.tgz", + "integrity": "sha512-jN46SEEe9EoXa3ZgZoKgnSF6z0w3tnM1yqhO4Y+Q4iZVc8JOQB960EZpIAz6rNROrDApVDwcMHR0mhlnc/5Omw==", + "dependencies": { + "swagger-ui-dist": ">=4.1.3" + }, + "engines": { + "node": ">= v0.10.32" + }, + "peerDependencies": { + "express": ">=4.0.0" + } + }, "node_modules/symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", @@ -10894,6 +10959,12 @@ "jsonwebtoken": "8.5.1" } }, + "@nestjs/mapped-types": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-1.0.1.tgz", + "integrity": "sha512-NFvofzSinp00j5rzUd4tf+xi9od6383iY0JP7o0Bnu1fuItAUkWBgc4EKuIQ3D+c2QI3i9pG1kDWAeY27EMGtg==", + "requires": {} + }, "@nestjs/passport": { "version": "8.2.1", "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-8.2.1.tgz", @@ -10978,6 +11049,16 @@ } } }, + "@nestjs/swagger": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-5.2.1.tgz", + "integrity": "sha512-7dNa08WCnTsW/oAk3Ujde+z64JMfNm19DhpXasFR8oJp/9pggYAbYU927HpA+GJsSFJX6adjIRZsCKUqaGWznw==", + "requires": { + "@nestjs/mapped-types": "1.0.1", + "lodash": "4.17.21", + "path-to-regexp": "3.2.0" + } + }, "@nestjs/testing": { "version": "8.4.3", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.3.tgz", @@ -16218,6 +16299,19 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "swagger-ui-dist": { + "version": "4.10.3", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.10.3.tgz", + "integrity": "sha512-eR4vsd7sYo0Sx7ZKRP5Z04yij7JkNmIlUQfrDQgC+xO5ABYx+waabzN+nDsQTLAJ4Z04bjkRd8xqkJtbxr3G7w==" + }, + "swagger-ui-express": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.3.0.tgz", + "integrity": "sha512-jN46SEEe9EoXa3ZgZoKgnSF6z0w3tnM1yqhO4Y+Q4iZVc8JOQB960EZpIAz6rNROrDApVDwcMHR0mhlnc/5Omw==", + "requires": { + "swagger-ui-dist": ">=4.1.3" + } + }, "symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", diff --git a/package.json b/package.json index 7efe846..7296854 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@nestjs/passport": "^8.2.1", "@nestjs/platform-express": "^8.0.0", "@nestjs/schedule": "^1.1.0", + "@nestjs/swagger": "^5.2.1", "@nestjs/typeorm": "^8.0.3", "bcrypt": "^5.0.1", "class-transformer": "^0.5.1", @@ -40,6 +41,7 @@ "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0", + "swagger-ui-express": "^4.3.0", "typeorm": "^0.2.45" }, "devDependencies": { diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 4ccded8..ee2e6b2 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -2,8 +2,10 @@ import { Body, Controller, Post } from '@nestjs/common'; import { AuthService } from './auth.service'; import { AuthLoginOperadorDto } from './dto/auth-login-operador.dto'; import { AuthLoginUsuarioDto } from './dto/auth-login-usuario.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('auth') +@ApiTags('auth') export class AuthController { constructor(private authService: AuthService) {} diff --git a/src/carrera-programa/carrera-programa.controller.ts b/src/carrera-programa/carrera-programa.controller.ts index 0b5dc24..289b5ec 100644 --- a/src/carrera-programa/carrera-programa.controller.ts +++ b/src/carrera-programa/carrera-programa.controller.ts @@ -2,8 +2,10 @@ 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'; +import {ApiTags} from '@nestjs/swagger' @Controller('carrera-programa') +@ApiTags('carrera-programa') export class CarreraProgramaController { constructor(private carreraProgramaService: CarreraProgramaService) {} diff --git a/src/carrera/carrera.controller.ts b/src/carrera/carrera.controller.ts index 436f540..5c57578 100644 --- a/src/carrera/carrera.controller.ts +++ b/src/carrera/carrera.controller.ts @@ -1,8 +1,10 @@ import { Controller, Get, Query } from '@nestjs/common'; import { CarreraService } from './carrera.service'; import { CarritoGetDto } from './dto/carrera-get-dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('carrera') +@ApiTags('carrera') export class CarreraController { constructor(private carreraService: CarreraService) {} diff --git a/src/carrito/carrito.controller.ts b/src/carrito/carrito.controller.ts index 6130ef3..e167350 100644 --- a/src/carrito/carrito.controller.ts +++ b/src/carrito/carrito.controller.ts @@ -4,8 +4,10 @@ import { CarritoCreateDto } from './dto/carrito-create.dto'; import { CarritoUpdateDto } from './dto/carrito-update.dto'; import { CarritoGetDto } from './dto/carrito-get-dto'; import { CarritoDto } from './dto/carrito.dto' +import {ApiTags} from '@nestjs/swagger' @Controller('carrito') +@ApiTags('carrito') export class CarritoController { constructor(private carritoService: CarritoService) {} diff --git a/src/equipo/equipo.controller.ts b/src/equipo/equipo.controller.ts index f31e766..cbb56db 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -1,8 +1,10 @@ import { Controller, Get, Post, Put, Query } from '@nestjs/common'; import { EquipoService } from './equipo.service'; import { EquipoDto } from './dto/equipo.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('equipo') +@ApiTags('equipo') export class EquipoController { constructor(private equipoService: EquipoService) {} diff --git a/src/hora-excepcion/hora-excepcion.controller.ts b/src/hora-excepcion/hora-excepcion.controller.ts index 67d4eab..63f9487 100644 --- a/src/hora-excepcion/hora-excepcion.controller.ts +++ b/src/hora-excepcion/hora-excepcion.controller.ts @@ -1,9 +1,10 @@ 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' - +import {ApiTags} from '@nestjs/swagger' @Controller('hora-excepcion') +@ApiTags('hora-excepcion') export class HoraExcepcionController { constructor(private horaExcepcionService: HoraExcepcionService) {} diff --git a/src/institucion-dia/institucion-dia.controller.ts b/src/institucion-dia/institucion-dia.controller.ts index 319ec51..839d129 100644 --- a/src/institucion-dia/institucion-dia.controller.ts +++ b/src/institucion-dia/institucion-dia.controller.ts @@ -2,8 +2,10 @@ import { Body, Controller, Get, Put, Query } from '@nestjs/common'; import { InstitucionDiaService } from './institucion-dia.service'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; import { InstitucionDiaUpdateDto } from './dto/institucion-dia-update.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('institucion-dia') +@ApiTags('institucion-dia') export class InstitucionDiaController { constructor(private institucionDiaService: InstitucionDiaService) {} diff --git a/src/institucion-infraccion/institucion-infraccion.controller.ts b/src/institucion-infraccion/institucion-infraccion.controller.ts index eea12b3..ed599a5 100644 --- a/src/institucion-infraccion/institucion-infraccion.controller.ts +++ b/src/institucion-infraccion/institucion-infraccion.controller.ts @@ -3,8 +3,10 @@ import { InstitucionInfraccionService } from './institucion-infraccion.service'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; import { InstitucionInfraccionCreateDto } from './dto/institucion-infraccion-create.dto'; import { InstitucionInfraccionUpdateDto } from './dto/institucion-infraccion-update.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('institucion-infraccion') +@ApiTags('institucion-infraccion') export class InstitucionInfraccionController { constructor( private institucionInfraccionService: InstitucionInfraccionService, diff --git a/src/institucion-tipo-carrito/institucion-tipo-carrito.controller.ts b/src/institucion-tipo-carrito/institucion-tipo-carrito.controller.ts index dd0e002..dd44a09 100644 --- a/src/institucion-tipo-carrito/institucion-tipo-carrito.controller.ts +++ b/src/institucion-tipo-carrito/institucion-tipo-carrito.controller.ts @@ -3,8 +3,10 @@ import { InstitucionTipoCarritoService } from './institucion-tipo-carrito.servic import { IdInstitucionDto } from '../dto/id-institucion.dto'; import { InstitucionTipoCarritoCreateDto } from './dto/institucion-tipo-carrito-create.dto'; import { InstitucionTipoCarritoUpdateDto } from './dto/institucion-tipo-carrito-update.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('institucion-tipo-carrito') +@ApiTags('institucion-tipo-carrito') export class InstitucionTipoCarritoController { constructor( private institucionTipoCarritoService: InstitucionTipoCarritoService, diff --git a/src/institucion/institucion.controller.ts b/src/institucion/institucion.controller.ts index 0d44379..00db265 100644 --- a/src/institucion/institucion.controller.ts +++ b/src/institucion/institucion.controller.ts @@ -2,8 +2,11 @@ import { Body, Controller, Get, Put, Query } from '@nestjs/common'; import { InstitucionService } from './institucion.service'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; import { InstitucionUpdateDto } from './dto/institucion-update.dto'; +import {ApiTags} from '@nestjs/swagger' + @Controller('institucion') +@ApiTags('institucion') export class InstitucionController { constructor(private institucionService: InstitucionService) {} diff --git a/src/main.ts b/src/main.ts index 52e2cb6..0e8110d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,19 @@ import { NestFactory } from '@nestjs/core'; +import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { ValidationPipe } from '@nestjs/common'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + + const config = new DocumentBuilder() + .setTitle('pcpuma_unam_api') + .setDescription('Api de Pc puma') + .setVersion('1.0') + .build(); + const document = SwaggerModule.createDocument(app, config); + SwaggerModule.setup('api', app, document); + app.useGlobalPipes(new ValidationPipe({ whitelist: true })); await app.listen(3000); } diff --git a/src/modulo/modulo.controller.ts b/src/modulo/modulo.controller.ts index 246c3dc..7f81c90 100644 --- a/src/modulo/modulo.controller.ts +++ b/src/modulo/modulo.controller.ts @@ -3,8 +3,11 @@ import { ModuloService } from './modulo.service'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; import { ModuloCreateDto } from './dto/modulo-create.dto'; import { ModuloUpdateDto } from './dto/modulo-update.dto'; +import {ApiTags} from '@nestjs/swagger' // import { Serealize } from '../interceptors/serialize.interceptor'; + @Controller('modulo') +@ApiTags('modulo') export class ModuloController { constructor(private moduloService: ModuloService) {} diff --git a/src/motivo/motivo.controller.ts b/src/motivo/motivo.controller.ts index ddcc168..4d4c0f8 100644 --- a/src/motivo/motivo.controller.ts +++ b/src/motivo/motivo.controller.ts @@ -1,7 +1,10 @@ import { Controller, Get, Query } from '@nestjs/common'; import { MotivoService } from './motivo.service'; import { MotivoDto } from './dto/motivo.dto'; +import {ApiTags} from '@nestjs/swagger' + @Controller('motivo') +@ApiTags('motivo') export class MotivoController { constructor(private motivoService: MotivoService) {} diff --git a/src/multa/multa.controller.ts b/src/multa/multa.controller.ts index 7f96f30..a96c457 100644 --- a/src/multa/multa.controller.ts +++ b/src/multa/multa.controller.ts @@ -1,7 +1,9 @@ import { Controller, Get } from '@nestjs/common'; import { MultaService } from './multa.service'; +import {ApiTags} from '@nestjs/swagger' @Controller('multa') +@ApiTags('multa') export class MultaController { constructor(private multaService: MultaService) {} diff --git a/src/operador/operador.controller.ts b/src/operador/operador.controller.ts index 9fec5e1..10159d4 100644 --- a/src/operador/operador.controller.ts +++ b/src/operador/operador.controller.ts @@ -4,7 +4,10 @@ import { OperadorCreateDto } from './dto/operador-create.dto'; import { OperadorOperadoresDto } from './dto/operador-operadores.dto'; import { OperadorUpdateDto } from './dto/operador-update.dto'; import { OperadorDto } from './dto/operador.dto'; +import {ApiTags} from '@nestjs/swagger' + @Controller('operador') +@ApiTags('operador') export class OperadorController { constructor(private operadorService: OperadorService) {} diff --git a/src/prestamo/prestamo.controller.ts b/src/prestamo/prestamo.controller.ts index 0abcfb2..cfd6369 100644 --- a/src/prestamo/prestamo.controller.ts +++ b/src/prestamo/prestamo.controller.ts @@ -1,7 +1,9 @@ import { Controller, Get, Post, Put } from '@nestjs/common'; import { PrestamoService } from './prestamo.service'; +import {ApiTags} from '@nestjs/swagger' @Controller('prestamo') +@ApiTags('prestamo') export class PrestamoController { constructor(private prestamoService: PrestamoService) {} diff --git a/src/programa/programa.controller.ts b/src/programa/programa.controller.ts index 346e428..d04647e 100644 --- a/src/programa/programa.controller.ts +++ b/src/programa/programa.controller.ts @@ -2,8 +2,10 @@ import { Body, Controller, Get, Post, Query } from '@nestjs/common'; import { ProgramaService } from './programa.service'; import { ProgramaCreateDto } from './dto/programa-create.dto'; import { ProgramaDto } from './dto/programa.dto' +import {ApiTags} from '@nestjs/swagger' @Controller('programa') +@ApiTags('programa') export class ProgramaController { constructor(private programaService: ProgramaService) {} diff --git a/src/status/status.controller.ts b/src/status/status.controller.ts index 5f048cf..c9ef101 100644 --- a/src/status/status.controller.ts +++ b/src/status/status.controller.ts @@ -1,7 +1,10 @@ import { Controller, Get } from '@nestjs/common'; import { StatusService } from './status.service'; +import {ApiTags} from '@nestjs/swagger' + @Controller('status') +@ApiTags('status') export class StatusController { constructor(private statusService: StatusService) {} diff --git a/src/tipo-entrada/tipo-entrada.controller.ts b/src/tipo-entrada/tipo-entrada.controller.ts index adcaba9..f3bf954 100644 --- a/src/tipo-entrada/tipo-entrada.controller.ts +++ b/src/tipo-entrada/tipo-entrada.controller.ts @@ -1,7 +1,9 @@ import { Controller, Get } from '@nestjs/common'; import { TipoEntradaService } from './tipo-entrada.service'; +import {ApiTags} from '@nestjs/swagger' @Controller('tipo-entrada') +@ApiTags('tipo-entrada') export class TipoEntradaController { constructor(private tipoEntradaService: TipoEntradaService) {} diff --git a/src/tipo-usuario/tipo-usuario.controller.ts b/src/tipo-usuario/tipo-usuario.controller.ts index 38d6487..1355e82 100644 --- a/src/tipo-usuario/tipo-usuario.controller.ts +++ b/src/tipo-usuario/tipo-usuario.controller.ts @@ -1,7 +1,10 @@ import { Body, Controller, Get, Post } from '@nestjs/common'; import { TipoUsuarioService } from './tipo-usuario.service'; import { TipoUsuarioUpdateDto } from './dto/tipo-usuario-update.dto'; +import {ApiTags} from '@nestjs/swagger' + @Controller('tipo-usuario') +@ApiTags('tipo-usuario') export class TipoUsuarioController { constructor(private tipoUsuarioService: TipoUsuarioService) {} diff --git a/src/upload-file/upload-file.controller.ts b/src/upload-file/upload-file.controller.ts index 4c81f08..081153c 100644 --- a/src/upload-file/upload-file.controller.ts +++ b/src/upload-file/upload-file.controller.ts @@ -10,8 +10,10 @@ import { import { FileInterceptor } from '@nestjs/platform-express'; import { UploadFileService } from './upload-file.service'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; +import {ApiTags} from '@nestjs/swagger' @Controller('upload-file') +@ApiTags('upload-file') export class UploadFileController { constructor(private uploadFileService: UploadFileService) {} diff --git a/src/usuario/usuario.controller.ts b/src/usuario/usuario.controller.ts index 08ae44a..8074bb8 100644 --- a/src/usuario/usuario.controller.ts +++ b/src/usuario/usuario.controller.ts @@ -14,8 +14,11 @@ import { UsuarioUpdateDto } from './dto/usuario-update.dto'; import { UsuarioUsuariosDto } from './dto/usuario-usuarios.dto'; import { UsuarioDto } from './dto/usuario.dto'; import { AuthGuard } from '@nestjs/passport'; +import {ApiTags} from '@nestjs/swagger' + @Controller('usuario') +@ApiTags('usuario') export class UsuarioController { constructor(private usuarioService: UsuarioService) {} From 6c1acdcd1641b03cf1a8c2e78ac3365402af857a Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 1 May 2022 12:45:27 -0500 Subject: [PATCH 10/10] tipo-entrada --- .../dto/tipo-entrada-create.dto.ts | 6 ++++++ src/tipo-entrada/tipo-entrada.controller.ts | 14 ++++++++++--- src/tipo-entrada/tipo-entrada.service.ts | 21 +++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/tipo-entrada/dto/tipo-entrada-create.dto.ts diff --git a/src/tipo-entrada/dto/tipo-entrada-create.dto.ts b/src/tipo-entrada/dto/tipo-entrada-create.dto.ts new file mode 100644 index 0000000..7c09d61 --- /dev/null +++ b/src/tipo-entrada/dto/tipo-entrada-create.dto.ts @@ -0,0 +1,6 @@ +import { IsString } from 'class-validator'; + +export class TipoEntradaCreateDto { + @IsString() + tipo_entrada: string; +} diff --git a/src/tipo-entrada/tipo-entrada.controller.ts b/src/tipo-entrada/tipo-entrada.controller.ts index f3bf954..cf11e72 100644 --- a/src/tipo-entrada/tipo-entrada.controller.ts +++ b/src/tipo-entrada/tipo-entrada.controller.ts @@ -1,12 +1,20 @@ -import { Controller, Get } from '@nestjs/common'; +import { Body, Controller, Get, Post } from '@nestjs/common'; import { TipoEntradaService } from './tipo-entrada.service'; -import {ApiTags} from '@nestjs/swagger' +import { TipoEntradaCreateDto } from './dto/tipo-entrada-create.dto' +import { ApiTags } from '@nestjs/swagger' @Controller('tipo-entrada') @ApiTags('tipo-entrada') export class TipoEntradaController { constructor(private tipoEntradaService: TipoEntradaService) {} + @Post() + create(@Body() body: TipoEntradaCreateDto) { + return this.tipoEntradaService.create(body.tipo_entrada) + } + @Get() - get() {} + get() { + return this.tipoEntradaService.findAll() + } } diff --git a/src/tipo-entrada/tipo-entrada.service.ts b/src/tipo-entrada/tipo-entrada.service.ts index 76efa73..9f73af0 100644 --- a/src/tipo-entrada/tipo-entrada.service.ts +++ b/src/tipo-entrada/tipo-entrada.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, ConflictException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { TipoEntrada } from './entity/tipo-entrada.entity'; @@ -7,5 +7,22 @@ import { TipoEntrada } from './entity/tipo-entrada.entity'; export class TipoEntradaService { constructor( @InjectRepository(TipoEntrada) private repository: Repository, - ) {} + ) { } + + async create(tipo_entrada: string) { + const nuevoTipoEntrada = this.repository.create({ + tipo_entrada + }) + + return this.repository.findOne({ tipo_entrada }) + .then((existeTipoEntrada) => { + if(existeTipoEntrada) throw new ConflictException('Ya existe este tipo de entrada') + return this.repository.save(nuevoTipoEntrada) + }) + .then(()=> ({message: 'Se creo correctamente la nueva entrada'})) + } + + findAll() { + return this.repository.find() + } }