revisar update y falta delete

This commit is contained in:
Andres2908
2022-04-20 23:22:34 -05:00
parent 8f480f1317
commit b386bd61e8
7 changed files with 106 additions and 8 deletions
+6
View File
@@ -0,0 +1,6 @@
import { IsOptional, IsString } from 'class-validator';
export class ProgramaDto {
@IsString()
id_programa: string;
}
+7 -1
View File
@@ -1,6 +1,7 @@
import { Body, Controller, Get, Post } from '@nestjs/common';
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { ProgramaService } from './programa.service';
import { ProgramaCreateDto } from './dto/programa-create.dto';
import { ProgramaDto } from './dto/programa.dto'
@Controller('programa')
export class ProgramaController {
@@ -15,4 +16,9 @@ export class ProgramaController {
get() {
return this.programaService.findAll();
}
@Get('programa')
programa(@Query() query: ProgramaDto) {
return this.programaService.findById(Number(query.id_programa))
}
}
+8 -1
View File
@@ -1,4 +1,4 @@
import { ConflictException, Injectable } from '@nestjs/common';
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Programa } from './entity/programa.entity';
@@ -23,4 +23,11 @@ export class ProgramaService {
findAll() {
return this.repository.find();
}
findById(id_programa: number) {
return this.repository.findOne({ id_programa }).then((programa) => {
if(!programa) throw new NotFoundException('No existe este programa')
return programa
})
}
}