2022-07-05 21:53:47 -05:00
|
|
|
import {
|
|
|
|
|
Body,
|
2022-07-31 22:02:07 -05:00
|
|
|
ConflictException,
|
2022-07-05 21:53:47 -05:00
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Query,
|
2022-07-31 22:02:07 -05:00
|
|
|
Request,
|
2022-07-05 21:53:47 -05:00
|
|
|
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-07-31 22:02:07 -05:00
|
|
|
import { Operador } from 'src/operador/entity/operador.entity';
|
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-07-31 22:02:07 -05:00
|
|
|
create(@Request() req, @Body() body: CreateCarreraProgramaDto) {
|
|
|
|
|
const admin: Operador = req.user.operador;
|
|
|
|
|
|
2022-08-01 01:30:41 -05:00
|
|
|
if (!admin || admin.tipoUsuario.id_tipo_usuario != 3)
|
2022-07-31 22:02:07 -05:00
|
|
|
throw new ConflictException('No tienes permiso de realizar esta acción.');
|
2022-04-22 13:36:18 -05:00
|
|
|
return this.carreraProgramaService.create(
|
2022-07-31 22:02:07 -05:00
|
|
|
admin,
|
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-07-31 22:02:07 -05:00
|
|
|
delete(@Request() req, @Body() body: DeleteCarreraProgramaDto) {
|
|
|
|
|
const admin: Operador = req.user.operador;
|
|
|
|
|
|
2022-08-01 01:30:41 -05:00
|
|
|
if (!admin || admin.tipoUsuario.id_tipo_usuario != 3)
|
2022-07-31 22:02:07 -05:00
|
|
|
throw new ConflictException('No tienes permiso de realizar esta acción.');
|
|
|
|
|
return this.carreraProgramaService.delete(admin, 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
|
|
|
}
|