carrera
This commit is contained in:
parent
12961f99b7
commit
8f480f1317
@ -1,13 +1,18 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
import { CarreraService } from './carrera.service';
|
import { CarreraService } from './carrera.service';
|
||||||
|
import {CarritoGetDto} from './dto/carrera-get-dto'
|
||||||
|
|
||||||
@Controller('carrera')
|
@Controller('carrera')
|
||||||
export class CarreraController {
|
export class CarreraController {
|
||||||
constructor(private carreraService: CarreraService) {}
|
constructor(private carreraService: CarreraService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
get() {}
|
get() {
|
||||||
|
return this.carreraService.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
@Get("carreras")
|
@Get("carreras")
|
||||||
carreras() {}
|
carreras(@Query() query: CarritoGetDto) {
|
||||||
|
return this.carreraService.findById(Number(query.id_carrera))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { ConflictException,
|
||||||
|
Injectable,
|
||||||
|
NotFoundException,} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Carrera } from './entity/carrera.entity';
|
import { Carrera } from './entity/carrera.entity';
|
||||||
@ -7,5 +9,16 @@ import { Carrera } from './entity/carrera.entity';
|
|||||||
export class CarreraService {
|
export class CarreraService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Carrera) private repository: Repository<Carrera>,
|
@InjectRepository(Carrera) private repository: Repository<Carrera>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return this.repository.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
findById(id_carrera: number) {
|
||||||
|
return this.repository.findOne({ id_carrera }).then((carrera) => {
|
||||||
|
if (!carrera) throw new NotFoundException('No existe esta carrera')
|
||||||
|
return carrera
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
src/carrera/dto/carrera-get-dto.ts
Normal file
6
src/carrera/dto/carrera-get-dto.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class CarritoGetDto {
|
||||||
|
@IsString()
|
||||||
|
id_carrera: string;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
|
import { IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class CarritoGetDto {
|
export class CarritoGetDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
Loading…
Reference in New Issue
Block a user