institucion carrera service final

This commit is contained in:
lemuel 2022-12-20 18:41:01 -06:00
parent 63177db2d6
commit 67a8d8f23f
4 changed files with 58 additions and 45 deletions

View File

@ -229,12 +229,7 @@ export class EquipoService {
validarNoExiste = true,
): Promise<Equipo> {
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(

View File

@ -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()

View File

@ -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<InstitucionCarrera[]> {
return this.institucionCarreraRepository.find({
where: { institucion: admin.institucion },
order: { carrera: { carrera: 'ASC' } },
});
}
findAllByIdInstitucion(id_institucion: number) {
findAllByIdInstitucion(
id_institucion: number,
): Promise<InstitucionCarrera[]> {
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<InstitucionCarrera> {
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<InstitucionCarrera> {
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<Carrera> {
return this.carreraRepository
.findOne({ where: { carrera } })
.then((carrera) => {
@ -80,7 +68,16 @@ export class InstitucionCarreraService {
});
}
findInstitucionProfesor(id_institucion: number) {
findCarreraByIdCarrera(id_carrera: number): Promise<Carrera> {
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<InstitucionCarrera> {
return this.institucionService
.findById(id_institucion)
.then((institucion) =>

View File

@ -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