institucion programa endpoints restringidos a usuario
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
Body,
|
||||
ConflictException,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
Request,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
@@ -17,6 +19,8 @@ import {
|
||||
} from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { InstitucionProgramaService } from './institucion-programa.service';
|
||||
import { Operador } from 'src/operador/entity/operador.entity';
|
||||
import { Usuario } from 'src/usuario/entity/usuario.entity';
|
||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||
import { CreateProgramaDto } from './dto/input/create.dto';
|
||||
import { UpdateProgramaDto } from './dto/input/update.dto';
|
||||
@@ -37,7 +41,11 @@ export class InstitucionProgramaController {
|
||||
description: 'Es obligatorio mandar la varible programa.',
|
||||
examples: { ejemplo: { value: { programa: '' } } },
|
||||
})
|
||||
create(@Body() body: CreateProgramaDto) {
|
||||
create(@Request() req, @Body() body: CreateProgramaDto) {
|
||||
const superAdmin: Operador = req.user.operador;
|
||||
|
||||
if (superAdmin.tipoUsuario.id_tipo_usuario != 2)
|
||||
throw new ConflictException('No tienes permiso de realizar esta acción.');
|
||||
return this.institucionProgramaService.create(body.programa);
|
||||
}
|
||||
|
||||
@@ -46,7 +54,16 @@ export class InstitucionProgramaController {
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que retorna todos los programas.' })
|
||||
@ApiBearerAuth('jwt')
|
||||
get() {
|
||||
get(@Request() req) {
|
||||
const admin: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
admin.tipoUsuario.id_tipo_usuario != 2 &&
|
||||
admin.tipoUsuario.id_tipo_usuario != 3
|
||||
)
|
||||
throw new ConflictException(
|
||||
'No tienes permiso de acceder a esta información.',
|
||||
);
|
||||
return this.institucionProgramaService.findAllProgramas();
|
||||
}
|
||||
|
||||
@@ -62,7 +79,13 @@ export class InstitucionProgramaController {
|
||||
name: 'id_institucion',
|
||||
type: 'string',
|
||||
})
|
||||
programas(@Query() query: IdInstitucionDto) {
|
||||
programas(@Request() req, @Query() query: IdInstitucionDto) {
|
||||
const admin: Operador = req.user.operador;
|
||||
|
||||
if (admin.tipoUsuario.id_tipo_usuario != 3)
|
||||
throw new ConflictException(
|
||||
'No tienes permiso de acceder a esta información.',
|
||||
);
|
||||
return this.institucionProgramaService.findAllByIdInstitucion(
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
@@ -81,7 +104,13 @@ export class InstitucionProgramaController {
|
||||
name: 'id_institucion',
|
||||
type: 'string',
|
||||
})
|
||||
programasMostrar(@Query() query: IdInstitucionDto) {
|
||||
programasMostrar(@Request() req, @Query() query: IdInstitucionDto) {
|
||||
const usuario: Usuario = req.user.operador;
|
||||
|
||||
if (usuario.tipoUsuario.id_tipo_usuario < 5)
|
||||
throw new ConflictException(
|
||||
'No tienes permiso de acceder a esta información.',
|
||||
);
|
||||
return this.institucionProgramaService.findAllByIdInstitucion(
|
||||
parseInt(query.id_institucion),
|
||||
true,
|
||||
@@ -101,7 +130,11 @@ export class InstitucionProgramaController {
|
||||
ejemplo: { value: { id_institucion_programa: 130, mostrar: true } },
|
||||
},
|
||||
})
|
||||
update(@Body() body: UpdateProgramaDto) {
|
||||
return this.institucionProgramaService.update(body);
|
||||
update(@Request() req, @Body() body: UpdateProgramaDto) {
|
||||
const admin: Operador = req.user.operador;
|
||||
|
||||
if (admin.tipoUsuario.id_tipo_usuario != 3)
|
||||
throw new ConflictException('No tienes permiso de realizar esta acción.');
|
||||
return this.institucionProgramaService.update(admin, body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user