carrera-programa

This commit is contained in:
Andres2908 2022-04-24 19:09:22 -05:00
parent 0bf224d1d2
commit 2a6d0c6219
2 changed files with 12 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, Post, Put } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
import { CarreraProgramaService } from './carrera-programa.service';
import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto';
import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto';
@ -16,16 +16,13 @@ export class CarreraProgramaController {
}
// terminar delte
@Delete()
delete() {}
@Delete(':id')
delete(@Param('id') id_carrera_programa: number) {
return this.carreraProgramaService.delete(id_carrera_programa)
}
@Get()
get() {
return this.carreraProgramaService.findAll();
}
@Put()
update(@Body() body: CarreraProgramaUpdateDto) {
return this.carreraProgramaService.update(body);
}
}

View File

@ -47,25 +47,16 @@ export class CarreraProgramaService {
.findOne({ id_carrera_programa })
.then((carreraPrograma) => {
if (!carreraPrograma)
throw new NotFoundException('No existe esta carrera programa');
throw new NotFoundException('No existe esta carrera-programa');
return carreraPrograma;
});
}
// Eliminar update, no tiene sentido tenerlo, me equivoque xd
async update(attrs: Partial<CarreraPrograma>) {
const carreraPrograma = await this.findById(attrs.id_carrera_programa);
return this.repository
.findOne({ id_carrera_programa: attrs.id_carrera_programa })
.then((existeCarreraPrograma) => {
if (existeCarreraPrograma)
throw new ConflictException('Ya existe esta carrera programa');
Object.assign(carreraPrograma, attrs);
return this.repository.save(carreraPrograma);
})
.then(() => ({
message: 'Se actualizo correctamente la carrera programa',
}));
//No estoy seguro de que esto este bien :)
delete(id_carrera_programa: number) {
this.findById(id_carrera_programa)
.then(() => {
return this.repository.delete(id_carrera_programa)
})
}
}