diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index 205256f..6c3dce2 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -229,12 +229,7 @@ export class EquipoService { validarNoExiste = true, ): Promise { return this.informacionEquipoView - .findOne({ - where: { - id_carrito: carrito.id_carrito, - equipo, - }, - }) + .findOne({ where: { id_carrito: carrito.id_carrito, equipo } }) .then((infoEquipo) => { if (!infoEquipo && validarNoExiste) throw new NotFoundException( diff --git a/src/institucion-carrera/institucion-carrera.controller.ts b/src/institucion-carrera/institucion-carrera.controller.ts index 1caa304..c077df9 100644 --- a/src/institucion-carrera/institucion-carrera.controller.ts +++ b/src/institucion-carrera/institucion-carrera.controller.ts @@ -1,14 +1,39 @@ -import { Controller, Get, Query } from '@nestjs/common'; -import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'; +import { Controller, Get, Query, Request, UseGuards } from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; +import { + ApiBearerAuth, + ApiOperation, + ApiQuery, + ApiTags, +} from '@nestjs/swagger'; import { Serealize } from '../interceptors/serialize.interceptor'; import { InstitucionCarreraService } from './institucion-carrera.service'; +import { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service'; +import { Operador } from '../operador/entity/operador.entity'; import { IdInstitucionDto } from '../dto/input/id-institucion.dto'; import { InstitucionCarreaOutputDto } from './dto/output/institucion-carrera.dto'; @Controller('institucion-carrera') @ApiTags('institucion-carrera') export class InstitucionCarreraController { - constructor(private institucionCarreraService: InstitucionCarreraService) {} + constructor( + private institucionCarreraService: InstitucionCarreraService, + private validarUsuarioService: ValidarUsuarioService, + ) {} + + @Serealize(InstitucionCarreaOutputDto) + @Get('admin') + @UseGuards(AuthGuard('jwt')) + @ApiOperation({ + description: 'Todas las carreras de la institución de un admin.', + }) + @ApiBearerAuth('jwt') + admin(@Request() req) { + const admin: Operador = req.user.operador; + + this.validarUsuarioService.validarAdmin(admin); + return this.institucionCarreraService.findAllAdmin(admin); + } @Serealize(InstitucionCarreaOutputDto) @Get() diff --git a/src/institucion-carrera/institucion-carrera.service.ts b/src/institucion-carrera/institucion-carrera.service.ts index 7f8f0aa..bdec3b5 100644 --- a/src/institucion-carrera/institucion-carrera.service.ts +++ b/src/institucion-carrera/institucion-carrera.service.ts @@ -4,6 +4,7 @@ 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 { Operador } from '../operador/entity/operador.entity'; import { InstitucionService } from '../institucion/institucion.service'; @Injectable() @@ -15,25 +16,27 @@ export class InstitucionCarreraService { private institucionService: InstitucionService, ) {} - crearInstitucionCarrera(id_institucion_carrera: number) { - return this.institucionCarreraRepository.create({ id_institucion_carrera }); + findAllAdmin(admin: Operador): Promise { + return this.institucionCarreraRepository.find({ + where: { institucion: admin.institucion }, + order: { carrera: { carrera: 'ASC' } }, + }); } - findAllByIdInstitucion(id_institucion: number) { + findAllByIdInstitucion( + id_institucion: number, + ): Promise { return this.institucionService .findById(id_institucion) .then((institucion) => this.institucionCarreraRepository.find({ - where: { - carrera: { id_carrera: Not(1) }, - institucion, - }, + where: { carrera: { id_carrera: Not(1) }, institucion }, order: { carrera: { carrera: 'ASC' } }, }), ); } - findById(id_institucion_carrera: number) { + findById(id_institucion_carrera: number): Promise { return this.institucionCarreraRepository .findOne({ where: { id_institucion_carrera } }) .then((institucionCarrera) => { @@ -43,34 +46,19 @@ export class InstitucionCarreraService { }); } - async findByIdInstitucionIdCarrera( - id_institucion: number | Institucion, - id_carrera: number | Carrera, - ) { - const carrera = - typeof id_carrera === 'number' - ? await this.findCarreraByIdCarrera(id_carrera) - : id_carrera; - const institucion = - typeof id_institucion === 'number' - ? await this.institucionService.findById(id_institucion) - : id_institucion; - + findByIdInstitucionIdCarrera( + institucion: Institucion, + carrera: Carrera, + ): Promise { return this.institucionCarreraRepository.findOne({ where: { carrera, institucion }, }); } - findCarreraByIdCarrera(id_carrera: number) { - return this.carreraRepository - .findOne({ where: { id_carrera } }) - .then((carrera) => { - if (!carrera) throw new NotFoundException('No existe este id carrera.'); - return carrera; - }); - } - - findCarreraByCarrera(carrera: string, validarNoExiste = true) { + findCarreraByCarrera( + carrera: string, + validarNoExiste = true, + ): Promise { return this.carreraRepository .findOne({ where: { carrera } }) .then((carrera) => { @@ -80,7 +68,16 @@ export class InstitucionCarreraService { }); } - findInstitucionProfesor(id_institucion: number) { + findCarreraByIdCarrera(id_carrera: number): Promise { + return this.carreraRepository + .findOne({ where: { id_carrera } }) + .then((carrera) => { + if (!carrera) throw new NotFoundException('No existe este id carrera.'); + return carrera; + }); + } + + findInstitucionProfesor(id_institucion: number): Promise { return this.institucionService .findById(id_institucion) .then((institucion) => diff --git a/src/institucion-programa/institucion-programa.service.ts b/src/institucion-programa/institucion-programa.service.ts index 2d9ed92..4a60989 100644 --- a/src/institucion-programa/institucion-programa.service.ts +++ b/src/institucion-programa/institucion-programa.service.ts @@ -48,10 +48,6 @@ export class InstitucionProgramaService { }); } - crearPrograma(id_programa: number) { - return this.programaRepository.create({ id_programa }); - } - async findAllByIdInstitucion(id_institucion: number, mostrar = false) { const institucion = await this.institucionService.findById(id_institucion); const query = this.institucionProgramaRepository