Files
pcpuma_unam_api/src/carrera-programa/carrera-programa.controller.ts
T

84 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-07-05 21:53:47 -05:00
import {
Body,
Controller,
Delete,
Get,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
2022-07-15 00:27:30 -05:00
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiQuery,
ApiTags,
} from '@nestjs/swagger';
2022-06-13 23:28:47 -05:00
import { Serealize } from '../interceptors/serialize.interceptor';
2022-04-04 20:53:32 -05:00
import { CarreraProgramaService } from './carrera-programa.service';
2022-06-13 05:47:21 -05:00
import { IdInstitucionDto } from '../dto/id-institucion.dto';
2022-06-13 23:28:47 -05:00
import { CreateCarreraProgramaDto } from './dto/input/create.dto';
import { DeleteCarreraProgramaDto } from './dto/input/delete.dto';
import { CarreraProgramaOutputDto } from './dto/output/carrera-programa.dto';
2022-03-31 14:33:11 -06:00
@Controller('carrera-programa')
2022-05-30 21:28:05 -05:00
@ApiTags('carrera-programa')
2022-04-04 20:53:32 -05:00
export class CarreraProgramaController {
constructor(private carreraProgramaService: CarreraProgramaService) {}
2022-04-17 20:47:35 -05:00
2022-04-17 20:56:02 -05:00
@Post()
2022-07-15 00:27:30 -05:00
@UseGuards(AuthGuard('jwt'))
2022-05-30 21:28:05 -05:00
@ApiOperation({
description:
2022-07-05 21:53:47 -05:00
'Endpoint que crea una asociación entre una carrera y un programa.',
2022-05-30 21:28:05 -05:00
})
2022-07-15 00:27:30 -05:00
@ApiBearerAuth('jwt')
2022-05-30 21:28:05 -05:00
@ApiBody({
description: 'Ambas variables son obligatorios.',
examples: {
ejemplo: { value: { id_institucion_carrera: 36, id_programa: 1 } },
},
})
2022-06-13 23:28:47 -05:00
create(@Body() body: CreateCarreraProgramaDto) {
2022-04-22 13:36:18 -05:00
return this.carreraProgramaService.create(
2022-05-30 21:28:05 -05:00
body.id_institucion_carrera,
2022-04-22 13:36:18 -05:00
body.id_programa,
);
2022-04-20 23:22:34 -05:00
}
2022-04-17 20:56:02 -05:00
2022-05-30 21:28:05 -05:00
@Delete()
2022-07-15 00:27:30 -05:00
@UseGuards(AuthGuard('jwt'))
2022-05-30 21:28:05 -05:00
@ApiOperation({
description:
'Endpoint que borra la asociación entre una carrera y un programa.',
})
2022-07-15 00:27:30 -05:00
@ApiBearerAuth('jwt')
2022-05-30 21:28:05 -05:00
@ApiBody({
2022-06-01 11:42:57 -05:00
description: 'Es obligatorio mandar la variable id_carrera_programa.',
2022-05-30 21:28:05 -05:00
examples: { ejemplo: { value: { id_carrera_programa: 1 } } },
})
2022-06-13 23:28:47 -05:00
delete(@Body() body: DeleteCarreraProgramaDto) {
2022-05-30 21:28:05 -05:00
return this.carreraProgramaService.delete(body.id_carrera_programa);
2022-04-24 19:09:22 -05:00
}
2022-04-17 20:56:02 -05:00
2022-06-13 23:28:47 -05:00
@Serealize(CarreraProgramaOutputDto)
2022-04-17 20:56:02 -05:00
@Get()
2022-07-15 01:06:13 -05:00
@UseGuards(AuthGuard('jwt'))
2022-05-30 21:28:05 -05:00
@ApiOperation({
description:
'Endpoint que retorna todos los programas reservados para una carrera de una institución.',
})
2022-07-15 01:06:13 -05:00
@ApiBearerAuth('jwt')
2022-05-30 21:28:05 -05:00
@ApiQuery({
description: 'Id de la institución.',
name: 'id_institucion',
type: 'string',
})
get(@Query() query: IdInstitucionDto) {
return this.carreraProgramaService.findByIdInstitucion(
parseInt(query.id_institucion),
);
2022-04-20 23:22:34 -05:00
}
2022-04-04 20:53:32 -05:00
}