carrera-programa
This commit is contained in:
parent
0bf224d1d2
commit
2a6d0c6219
@ -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 { CarreraProgramaService } from './carrera-programa.service';
|
||||||
import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto';
|
import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto';
|
||||||
import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto';
|
import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto';
|
||||||
@ -16,16 +16,13 @@ export class CarreraProgramaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// terminar delte
|
// terminar delte
|
||||||
@Delete()
|
@Delete(':id')
|
||||||
delete() {}
|
delete(@Param('id') id_carrera_programa: number) {
|
||||||
|
return this.carreraProgramaService.delete(id_carrera_programa)
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
get() {
|
get() {
|
||||||
return this.carreraProgramaService.findAll();
|
return this.carreraProgramaService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
|
||||||
update(@Body() body: CarreraProgramaUpdateDto) {
|
|
||||||
return this.carreraProgramaService.update(body);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -47,25 +47,16 @@ export class CarreraProgramaService {
|
|||||||
.findOne({ id_carrera_programa })
|
.findOne({ id_carrera_programa })
|
||||||
.then((carreraPrograma) => {
|
.then((carreraPrograma) => {
|
||||||
if (!carreraPrograma)
|
if (!carreraPrograma)
|
||||||
throw new NotFoundException('No existe esta carrera programa');
|
throw new NotFoundException('No existe esta carrera-programa');
|
||||||
return carreraPrograma;
|
return carreraPrograma;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eliminar update, no tiene sentido tenerlo, me equivoque xd
|
//No estoy seguro de que esto este bien :)
|
||||||
async update(attrs: Partial<CarreraPrograma>) {
|
delete(id_carrera_programa: number) {
|
||||||
const carreraPrograma = await this.findById(attrs.id_carrera_programa);
|
this.findById(id_carrera_programa)
|
||||||
|
.then(() => {
|
||||||
return this.repository
|
return this.repository.delete(id_carrera_programa)
|
||||||
.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',
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user