POSTprograms
This commit is contained in:
@@ -15,6 +15,10 @@ export class ProgramaController {
|
|||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
return this.programaService.findOne(+id);
|
return this.programaService.findOne(+id);
|
||||||
}
|
}
|
||||||
|
@Post()
|
||||||
|
create(@Body() body) {
|
||||||
|
return this.programaService.create(body);
|
||||||
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) {
|
update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) {
|
||||||
|
|||||||
@@ -15,19 +15,22 @@ export class ProgramaService {
|
|||||||
findAll() {
|
findAll() {
|
||||||
return this.programaRepository.find({order:{programa:'ASC'}});
|
return this.programaRepository.find({order:{programa:'ASC'}});
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id_programa: number) {
|
findOne(id_programa: number) {
|
||||||
const programa = this.programaRepository.findOne({where:{id_programa}})
|
return this.programaRepository.findOne({ where: { id_programa } });
|
||||||
|
|
||||||
if(!programa){
|
|
||||||
return "this program dosnt exist"
|
|
||||||
}
|
|
||||||
|
|
||||||
return programa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, updateProgramaDto: UpdateProgramaDto) {
|
// CREAR
|
||||||
return `This action updates a #${id} programa`;
|
async create(createProgramaDto: CreateProgramaDto) {
|
||||||
|
const nuevo = this.programaRepository.create(createProgramaDto);
|
||||||
|
return await this.programaRepository.save(nuevo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ACTUALIZAR
|
||||||
|
async update(id: number, updateProgramaDto: UpdateProgramaDto) {
|
||||||
|
await this.programaRepository.update(id, updateProgramaDto);
|
||||||
|
return await this.findOne(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user