From 0bf224d1d27ff2d831411e70e75165afdee2acd2 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sun, 24 Apr 2022 18:38:31 -0500 Subject: [PATCH] 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; }