diff --git a/src/equipo-tipo-entrada/entity/equipo-tipo-entrada.entity.ts b/src/equipo-tipo-entrada/entity/equipo-tipo-entrada.entity.ts index de39b13..3cfa650 100644 --- a/src/equipo-tipo-entrada/entity/equipo-tipo-entrada.entity.ts +++ b/src/equipo-tipo-entrada/entity/equipo-tipo-entrada.entity.ts @@ -11,11 +11,9 @@ export class EquipoTipoEntrada { @JoinColumn({ name: 'id_equipo' }) equipo: Equipo; - @ManyToOne( - () => TipoEntrada, - (tipoEntrada) => tipoEntrada.equiposTipoEntrada, - { eager: true }, - ) + @ManyToOne(() => TipoEntrada, (tipoEntrada) => tipoEntrada.equipos, { + eager: true, + }) @JoinColumn({ name: 'id_tipo_entrada' }) tipoEntrada: TipoEntrada; } diff --git a/src/institucion-carrera/institucion-carrera.service.ts b/src/institucion-carrera/institucion-carrera.service.ts index 1c30e74..9bc7067 100644 --- a/src/institucion-carrera/institucion-carrera.service.ts +++ b/src/institucion-carrera/institucion-carrera.service.ts @@ -4,7 +4,6 @@ import { Not, Repository } from 'typeorm'; import { Carrera } from '../institucion-carrera/entity/carrera.entity'; import { Institucion } from '../institucion/entity/institucion.entity'; import { InstitucionCarrera } from './entity/institucion-carrera.entity'; -import { Nivel } from './entity/nivel.entity'; import { InstitucionService } from '../institucion/institucion.service'; @Injectable() @@ -13,7 +12,6 @@ export class InstitucionCarreraService { @InjectRepository(Carrera) private carreraRepository: Repository, @InjectRepository(InstitucionCarrera) private institucionCarreraRepository: Repository, - @InjectRepository(Carrera) private nivelRepository: Repository, private institucionService: InstitucionService, ) {} diff --git a/src/institucion-infraccion/institucion-infraccion.service.ts b/src/institucion-infraccion/institucion-infraccion.service.ts index bef2c10..47b76b4 100644 --- a/src/institucion-infraccion/institucion-infraccion.service.ts +++ b/src/institucion-infraccion/institucion-infraccion.service.ts @@ -13,50 +13,50 @@ import { InstitucionService } from '../institucion/institucion.service'; export class InstitucionInfraccionService { constructor( @InjectRepository(Infraccion) - private repositoryInfraccion: Repository, + private infraccionRepository: Repository, @InjectRepository(InstitucionInfraccion) - private repositoryInstitucionInfraccion: Repository, + private institucionInfraccionRepository: Repository, private institucionService: InstitucionService, ) {} create(infraccion: string) { - return this.repositoryInfraccion + return this.infraccionRepository .findOne({ infraccion }) .then((existeInfraccion) => { if (existeInfraccion) throw new ConflictException('Ya existe esta infracción.'); - return this.repositoryInfraccion.save( - this.repositoryInfraccion.create({ infraccion }), + return this.infraccionRepository.save( + this.infraccionRepository.create({ infraccion }), ); }) .then(async (infraccion) => { const instituciones = await this.institucionService.findAll(); for (let i = 0; i < instituciones.length; i++) - await this.repositoryInstitucionInfraccion.save( - this.repositoryInstitucionInfraccion.create({ + await this.institucionInfraccionRepository.save( + this.institucionInfraccionRepository.create({ infraccion, institucion: instituciones[i], }), ); - return { message: 'Se creó creo correctamente una nueva infracción.' }; + return { message: 'Se creó correctamente una nueva infracción.' }; }); } findAll() { - return this.repositoryInfraccion.find(); + return this.infraccionRepository.find(); } findAllByIdInstitucion(id_institucion: number) { return this.institucionService .findById(id_institucion) .then((institucion) => - this.repositoryInstitucionInfraccion.find({ institucion }), + this.institucionInfraccionRepository.find({ institucion }), ); } findById(id_institucion_infraccion: number) { - return this.repositoryInstitucionInfraccion + return this.institucionInfraccionRepository .findOne({ id_institucion_infraccion }) .then((institucionInfraccion) => { if (!institucionInfraccion) @@ -69,7 +69,7 @@ export class InstitucionInfraccionService { return this.findById(attrs.id_institucion_infraccion) .then((institucionInfraccion) => { Object.assign(institucionInfraccion, attrs); - return this.repositoryInstitucionInfraccion.save(institucionInfraccion); + return this.institucionInfraccionRepository.save(institucionInfraccion); }) .then((_) => ({ message: 'Se guardaron los cambios correctamente.', diff --git a/src/institucion-programa/institucion-programa.service.ts b/src/institucion-programa/institucion-programa.service.ts index f05e522..76f08bc 100644 --- a/src/institucion-programa/institucion-programa.service.ts +++ b/src/institucion-programa/institucion-programa.service.ts @@ -36,8 +36,8 @@ export class InstitucionProgramaService { for (let i = 0; i < instituciones.length; i++) await this.institucionProgramaRepository.save( this.institucionProgramaRepository.create({ - programa, institucion: instituciones[i], + programa, }), ); return { message: 'Se creó correctamente un nuevo programa.' }; diff --git a/src/institucion-tipo-carrito/institucion-tipo-carrito.service.ts b/src/institucion-tipo-carrito/institucion-tipo-carrito.service.ts index f717571..901fb8e 100644 --- a/src/institucion-tipo-carrito/institucion-tipo-carrito.service.ts +++ b/src/institucion-tipo-carrito/institucion-tipo-carrito.service.ts @@ -14,14 +14,14 @@ import { InstitucionService } from '../institucion/institucion.service'; export class InstitucionTipoCarritoService { constructor( @InjectRepository(TipoCarrito) - private repositoryTipoCarrito: Repository, + private tipoCarritoRepository: Repository, @InjectRepository(InstitucionTipoCarrito) - private repositoryInstitucionTipoCarrito: Repository, + private institucionTipoCarritoRepository: Repository, private institucionService: InstitucionService, ) {} create(letra: string, tipo_carrito: string) { - return this.repositoryTipoCarrito + return this.tipoCarritoRepository .findOne({ where: [{ letra }, { tipo_carrito }] }) .then((existeTipoCarrito) => { if (existeTipoCarrito) { @@ -34,16 +34,16 @@ export class InstitucionTipoCarritoService { 'Ya existe un tipo carrito con este nombre, intente con otro nombre.', ); } - return this.repositoryTipoCarrito.save( - this.repositoryTipoCarrito.create({ letra, tipo_carrito }), + return this.tipoCarritoRepository.save( + this.tipoCarritoRepository.create({ letra, tipo_carrito }), ); }) .then(async (tipoCarrito) => { const instituciones = await this.institucionService.findAll(); for (let i = 0; i < instituciones.length; i++) - await this.repositoryInstitucionTipoCarrito.save( - this.repositoryInstitucionTipoCarrito.create({ + await this.institucionTipoCarritoRepository.save( + this.institucionTipoCarritoRepository.create({ institucion: instituciones[i], tipoCarrito, }), @@ -53,7 +53,7 @@ export class InstitucionTipoCarritoService { } findAll() { - return this.repositoryTipoCarrito.find(); + return this.tipoCarritoRepository.find(); } async findAllByIdInstitucion(id_institucion: number, mostrar = false) { @@ -63,11 +63,11 @@ export class InstitucionTipoCarritoService { }; if (mostrar) busqueda.mostrar = mostrar; - return this.repositoryInstitucionTipoCarrito.find(busqueda); + return this.institucionTipoCarritoRepository.find(busqueda); } findInstitucionTipoCarritoById(id_institucion_tipo_carrito) { - return this.repositoryInstitucionTipoCarrito + return this.institucionTipoCarritoRepository .findOne({ id_institucion_tipo_carrito, }) @@ -81,7 +81,7 @@ export class InstitucionTipoCarritoService { } findTipoCarritoById(id_tipo_carrito: number) { - return this.repositoryTipoCarrito + return this.tipoCarritoRepository .findOne({ id_tipo_carrito }) .then((tipoCarrito) => { if (!tipoCarrito) @@ -91,7 +91,7 @@ export class InstitucionTipoCarritoService { } findTipoCarritoByTipoCarrito(tipo_carrito: string, validarNoExiste = true) { - return this.repositoryTipoCarrito + return this.tipoCarritoRepository .findOne({ tipo_carrito }) .then((tipoCarrito) => { if (validarNoExiste && !tipoCarrito) @@ -106,7 +106,7 @@ export class InstitucionTipoCarritoService { ) .then((institucionTipoCarrito) => { Object.assign(institucionTipoCarrito, attrs); - return this.repositoryInstitucionTipoCarrito.save( + return this.institucionTipoCarritoRepository.save( institucionTipoCarrito, ); }) diff --git a/src/institucion-tipo-entrada/entity/tipo-entrada.entity.ts b/src/institucion-tipo-entrada/entity/tipo-entrada.entity.ts index f91c025..ec8e08f 100644 --- a/src/institucion-tipo-entrada/entity/tipo-entrada.entity.ts +++ b/src/institucion-tipo-entrada/entity/tipo-entrada.entity.ts @@ -14,7 +14,7 @@ export class TipoEntrada { () => EquipoTipoEntrada, (equipoTipoEntrada) => equipoTipoEntrada.tipoEntrada, ) - equiposTipoEntrada: EquipoTipoEntrada[]; + equipos: EquipoTipoEntrada[]; @OneToMany( () => InstitucionTipoEntrada, diff --git a/src/institucion-tipo-entrada/institucion-tipo-entrada.controller.ts b/src/institucion-tipo-entrada/institucion-tipo-entrada.controller.ts index d6aff3c..dbb2f6c 100644 --- a/src/institucion-tipo-entrada/institucion-tipo-entrada.controller.ts +++ b/src/institucion-tipo-entrada/institucion-tipo-entrada.controller.ts @@ -62,8 +62,9 @@ export class InstitucionTipoEntradaController { type: 'string', }) tipoEntradaMostrar(@Query() query: IdInstitucionDto) { - return this.tipoEntradaService.findAllByIdInstitucionMostrar( + return this.tipoEntradaService.findAllByIdInstitucion( parseInt(query.id_institucion), + true, ); } diff --git a/src/institucion-tipo-entrada/institucion-tipo-entrada.module.ts b/src/institucion-tipo-entrada/institucion-tipo-entrada.module.ts index 5b27efb..7d15f02 100644 --- a/src/institucion-tipo-entrada/institucion-tipo-entrada.module.ts +++ b/src/institucion-tipo-entrada/institucion-tipo-entrada.module.ts @@ -8,8 +8,8 @@ import { TipoEntrada } from './entity/tipo-entrada.entity'; @Module({ imports: [ - TypeOrmModule.forFeature([InstitucionTipoEntrada, TipoEntrada]), InstitucionModule, + TypeOrmModule.forFeature([InstitucionTipoEntrada, TipoEntrada]), ], controllers: [InstitucionTipoEntradaController], providers: [InstitucionTipoEntradaService], diff --git a/src/institucion-tipo-entrada/institucion-tipo-entrada.service.ts b/src/institucion-tipo-entrada/institucion-tipo-entrada.service.ts index 28787c0..c3d1e97 100644 --- a/src/institucion-tipo-entrada/institucion-tipo-entrada.service.ts +++ b/src/institucion-tipo-entrada/institucion-tipo-entrada.service.ts @@ -5,59 +5,65 @@ import { } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; +import { Institucion } from '../institucion/entity/institucion.entity'; import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity'; import { TipoEntrada } from './entity/tipo-entrada.entity'; -import { Institucion } from '../institucion/entity/institucion.entity'; import { InstitucionService } from '../institucion/institucion.service'; @Injectable() export class InstitucionTipoEntradaService { constructor( @InjectRepository(InstitucionTipoEntrada) - private repositoryInstitucionTipoEntrada: Repository, + private institucionTipoEntradaRepository: Repository, @InjectRepository(TipoEntrada) - private repositoryTipoEntrada: Repository, + private tipoEntradaRepository: Repository, private institucionService: InstitucionService, ) {} async create(tipo_entrada: string) { - // corregir - return this.repositoryTipoEntrada + return this.tipoEntradaRepository .findOne({ tipo_entrada }) .then((existeTipoEntrada) => { if (existeTipoEntrada) throw new ConflictException('Ya existe este tipo de entrada.'); - return this.repositoryTipoEntrada.save( - this.repositoryTipoEntrada.create({ + return this.tipoEntradaRepository.save( + this.tipoEntradaRepository.create({ tipo_entrada, }), ); }) - .then((_) => ({ message: 'Se creo correctamente la nueva entrada.' })); - } + .then(async (tipoEntrada) => { + const instituciones = await this.institucionService.findAll(); - findAll() { - return this.repositoryTipoEntrada.find(); - } - - findAllByIdInstitucion(id_institucion: number, mostrar = false) { - const busqueda: { institucion?: Institucion; mostrar?: boolean } = {}; - - if (mostrar) busqueda.mostrar = mostrar; - return this.institucionService - .findById(id_institucion) - .then((institucion) => { - busqueda.institucion = institucion; - return this.repositoryInstitucionTipoEntrada.find(busqueda); + for (let i = 0; i < instituciones.length; i++) + await this.institucionTipoEntradaRepository.save( + this.institucionTipoEntradaRepository.create({ + institucion: instituciones[i], + tipoEntrada, + }), + ); + return { + message: 'Se creó correctamente un nuevo tipo de entrada.', + }; }); } - findAllByIdInstitucionMostrar(id_institucion: number) { - return this.findAllByIdInstitucion(id_institucion, true); + findAll() { + return this.tipoEntradaRepository.find(); + } + + async findAllByIdInstitucion(id_institucion: number, mostrar = false) { + const institucion = await this.institucionService.findById(id_institucion); + const busqueda: { institucion: Institucion; mostrar?: boolean } = { + institucion, + }; + + if (mostrar) busqueda.mostrar = mostrar; + return this.institucionTipoEntradaRepository.find(busqueda); } findById(id_institucion_tipo_entrada: number) { - return this.repositoryInstitucionTipoEntrada + return this.institucionTipoEntradaRepository .findOne({ id_institucion_tipo_entrada, }) @@ -71,7 +77,7 @@ export class InstitucionTipoEntradaService { } findTipoEntradaById(id_tipo_entrada: number) { - return this.repositoryTipoEntrada + return this.tipoEntradaRepository .findOne({ id_tipo_entrada }) .then((tipoEntrada) => { if (!tipoEntrada) @@ -81,7 +87,7 @@ export class InstitucionTipoEntradaService { } findTipoEntradaByTipoEntrada(tipo_entrada: string, validarNoExiste = true) { - return this.repositoryTipoEntrada + return this.tipoEntradaRepository .findOne({ tipo_entrada }) .then((tipoEntrada) => { if (validarNoExiste && !tipoEntrada) @@ -94,13 +100,12 @@ export class InstitucionTipoEntradaService { return this.findById(attrs.id_institucion_tipo_entrada) .then((institucionTipoEntrada) => { Object.assign(institucionTipoEntrada, attrs); - return this.repositoryInstitucionTipoEntrada.save( + return this.institucionTipoEntradaRepository.save( institucionTipoEntrada, ); }) .then((_) => ({ - message: - 'Se actualizó correctamente la información de la institución tipo entrada.', + message: 'Se guardaron los cambios correctamente.', })); } }