modulo institución carrera final

This commit is contained in:
xXpuma99Xx
2022-06-22 11:19:33 -05:00
parent 68584e5a52
commit 6ee9ddd10a
3 changed files with 25 additions and 29 deletions
@@ -6,9 +6,6 @@ export class InstitucionCarreaOutputDto {
@Expose()
id_institucion_carrera;
@Expose()
clave_alt;
@Expose()
@Type(() => CarreaOutputDto)
carrera;
@@ -1,46 +1,30 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
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 { InstitucionService } from '../institucion/institucion.service';
import { Nivel } from './entity/nivel.entity';
import { InstitucionService } from '../institucion/institucion.service';
@Injectable()
export class InstitucionCarreraService {
constructor(
@InjectRepository(Carrera) private carreraRepository: Repository<Carrera>,
@InjectRepository(InstitucionCarrera)
private institucionCarreraRepository: Repository<InstitucionCarrera>,
@InjectRepository(Carrera) private carreraRepository: Repository<Carrera>,
@InjectRepository(Carrera) private nivelRepository: Repository<Nivel>,
private institucionService: InstitucionService,
) {}
findAllCarreras() {
return this.carreraRepository.find();
}
findCarreraByIdCarrera(id_carrera: number) {
return this.carreraRepository.findOne({ id_carrera }).then((carrera) => {
if (!carrera) throw new NotFoundException('No existe esta carrera.');
return carrera;
});
}
findCarreraByCarrera(carrera: string, validarNoExiste = true) {
return this.carreraRepository.findOne({ carrera }).then((carrera) => {
if (validarNoExiste && !carrera)
throw new NotFoundException('No existe esta carrera.');
return carrera;
});
}
findAllByIdInstitucion(id_institucion: number) {
return this.institucionService
.findById(id_institucion)
.then((institucion) =>
this.institucionCarreraRepository.find({ institucion }),
this.institucionCarreraRepository.find({
carrera: { id_carrera: Not(1) },
institucion,
}),
);
}
@@ -49,7 +33,7 @@ export class InstitucionCarreraService {
.findOne({ id_institucion_carrera })
.then((institucionCarrera) => {
if (!institucionCarrera)
throw new NotFoundException('No existe esta institución carrera.');
throw new NotFoundException('No existe este id institución carrera.');
return institucionCarrera;
});
}
@@ -69,4 +53,19 @@ export class InstitucionCarreraService {
return this.institucionCarreraRepository.findOne({ carrera, institucion });
}
findCarreraByIdCarrera(id_carrera: number) {
return this.carreraRepository.findOne({ id_carrera }).then((carrera) => {
if (!carrera) throw new NotFoundException('No existe esta carrera.');
return carrera;
});
}
findCarreraByCarrera(carrera: string, validarNoExiste = true) {
return this.carreraRepository.findOne({ carrera }).then((carrera) => {
if (validarNoExiste && !carrera)
throw new NotFoundException('No existe esta carrera.');
return carrera;
});
}
}
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Institucion } from '../institucion/entity/institucion.entity';
@@ -23,7 +23,7 @@ export class InstitucionDiaService {
.findOne({ id_institucion_dia })
.then((institucionDia) => {
if (!institucionDia)
throw new Error('No existe este id día institución.');
throw new NotFoundException('No existe este id institución día.');
return institucionDia;
});
}