institucion tipo carriot endpoints restringidos a usuario
This commit is contained in:
parent
cb04e3b0e4
commit
93118ea7bd
@ -40,13 +40,7 @@ export class InstitucionDiaController {
|
|||||||
name: 'id_institucion',
|
name: 'id_institucion',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
dias(@Request() req, @Query() query: IdInstitucionDto) {
|
dias(@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.institucionDiaService.findAllByIdInstitucion(
|
return this.institucionDiaService.findAllByIdInstitucion(
|
||||||
parseInt(query.id_institucion),
|
parseInt(query.id_institucion),
|
||||||
);
|
);
|
||||||
|
@ -54,13 +54,7 @@ export class InstitucionInfraccionController {
|
|||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@ApiOperation({ description: 'Endpoint que retorna todas las infracciones.' })
|
@ApiOperation({ description: 'Endpoint que retorna todas las infracciones.' })
|
||||||
@ApiBearerAuth('jwt')
|
@ApiBearerAuth('jwt')
|
||||||
get(@Request() req) {
|
get() {
|
||||||
const superAdmin: Operador = req.user.operador;
|
|
||||||
|
|
||||||
if (superAdmin.tipoUsuario.id_tipo_usuario != 2)
|
|
||||||
throw new ConflictException(
|
|
||||||
'No tienes permiso de acceder a esta información.',
|
|
||||||
);
|
|
||||||
return this.institucionInfraccionService.findAll();
|
return this.institucionInfraccionService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,16 +70,7 @@ export class InstitucionInfraccionController {
|
|||||||
name: 'id_institucion',
|
name: 'id_institucion',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
infracciones(@Request() req, @Query() query: IdInstitucionDto) {
|
infracciones(@Query() query: IdInstitucionDto) {
|
||||||
const operador: Operador = req.user.operador;
|
|
||||||
|
|
||||||
if (
|
|
||||||
operador.tipoUsuario.id_tipo_usuario != 3 &&
|
|
||||||
operador.tipoUsuario.id_tipo_usuario != 4
|
|
||||||
)
|
|
||||||
throw new ConflictException(
|
|
||||||
'No tienes permiso de acceder a esta información.',
|
|
||||||
);
|
|
||||||
return this.institucionInfraccionService.findAllByIdInstitucion(
|
return this.institucionInfraccionService.findAllByIdInstitucion(
|
||||||
parseInt(query.id_institucion),
|
parseInt(query.id_institucion),
|
||||||
);
|
);
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||||
import { InstitucionProgramaService } from './institucion-programa.service';
|
import { InstitucionProgramaService } from './institucion-programa.service';
|
||||||
import { Operador } from 'src/operador/entity/operador.entity';
|
import { Operador } from 'src/operador/entity/operador.entity';
|
||||||
import { Usuario } from 'src/usuario/entity/usuario.entity';
|
|
||||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||||
import { CreateProgramaDto } from './dto/input/create.dto';
|
import { CreateProgramaDto } from './dto/input/create.dto';
|
||||||
import { UpdateProgramaDto } from './dto/input/update.dto';
|
import { UpdateProgramaDto } from './dto/input/update.dto';
|
||||||
@ -54,16 +53,7 @@ export class InstitucionProgramaController {
|
|||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@ApiOperation({ description: 'Endpoint que retorna todos los programas.' })
|
@ApiOperation({ description: 'Endpoint que retorna todos los programas.' })
|
||||||
@ApiBearerAuth('jwt')
|
@ApiBearerAuth('jwt')
|
||||||
get(@Request() req) {
|
get() {
|
||||||
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();
|
return this.institucionProgramaService.findAllProgramas();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,13 +69,7 @@ export class InstitucionProgramaController {
|
|||||||
name: 'id_institucion',
|
name: 'id_institucion',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
programas(@Request() req, @Query() query: IdInstitucionDto) {
|
programas(@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(
|
return this.institucionProgramaService.findAllByIdInstitucion(
|
||||||
parseInt(query.id_institucion),
|
parseInt(query.id_institucion),
|
||||||
);
|
);
|
||||||
@ -104,13 +88,7 @@ export class InstitucionProgramaController {
|
|||||||
name: 'id_institucion',
|
name: 'id_institucion',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
programasMostrar(@Request() req, @Query() query: IdInstitucionDto) {
|
programasMostrar(@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(
|
return this.institucionProgramaService.findAllByIdInstitucion(
|
||||||
parseInt(query.id_institucion),
|
parseInt(query.id_institucion),
|
||||||
true,
|
true,
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
|
ConflictException,
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
|
Request,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
@ -17,6 +19,7 @@ import {
|
|||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||||
import { InstitucionTipoCarritoService } from './institucion-tipo-carrito.service';
|
import { InstitucionTipoCarritoService } from './institucion-tipo-carrito.service';
|
||||||
|
import { Operador } from 'src/operador/entity/operador.entity';
|
||||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||||
import { CreateInstitucionTipoCarritoDto } from './dto/input/create.dto';
|
import { CreateInstitucionTipoCarritoDto } from './dto/input/create.dto';
|
||||||
import { UpdateInstitucionTipoCarritoDto } from './dto/input/update.dto';
|
import { UpdateInstitucionTipoCarritoDto } from './dto/input/update.dto';
|
||||||
@ -39,7 +42,11 @@ export class InstitucionTipoCarritoController {
|
|||||||
examples: { ejemplo: { value: { letra: '', tipo_carrito: '' } } },
|
examples: { ejemplo: { value: { letra: '', tipo_carrito: '' } } },
|
||||||
})
|
})
|
||||||
@ApiBearerAuth('jwt')
|
@ApiBearerAuth('jwt')
|
||||||
create(@Body() body: CreateInstitucionTipoCarritoDto) {
|
create(@Request() req, @Body() body: CreateInstitucionTipoCarritoDto) {
|
||||||
|
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.institucionTipoCarritoService.create(
|
return this.institucionTipoCarritoService.create(
|
||||||
body.letra,
|
body.letra,
|
||||||
body.tipo_carrito,
|
body.tipo_carrito,
|
||||||
@ -109,7 +116,11 @@ export class InstitucionTipoCarritoController {
|
|||||||
ejemplo: { value: { id_institucion_tipo_carrito: 130, mostrar: true } },
|
ejemplo: { value: { id_institucion_tipo_carrito: 130, mostrar: true } },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
update(@Body() body: UpdateInstitucionTipoCarritoDto) {
|
update(@Request() req, @Body() body: UpdateInstitucionTipoCarritoDto) {
|
||||||
return this.institucionTipoCarritoService.update(body);
|
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.institucionTipoCarritoService.update(admin, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { InstitucionTipoCarrito } from './entity/institucion-tipo-carrito.entity';
|
import { InstitucionTipoCarrito } from './entity/institucion-tipo-carrito.entity';
|
||||||
|
import { Operador } from 'src/operador/entity/operador.entity';
|
||||||
import { TipoCarrito } from './entity/tipo-carrito.entity';
|
import { TipoCarrito } from './entity/tipo-carrito.entity';
|
||||||
import { InstitucionService } from '../institucion/institucion.service';
|
import { InstitucionService } from '../institucion/institucion.service';
|
||||||
|
|
||||||
@ -75,7 +76,11 @@ export class InstitucionTipoCarritoService {
|
|||||||
findInstitucionTipoCarritoById(id_institucion_tipo_carrito) {
|
findInstitucionTipoCarritoById(id_institucion_tipo_carrito) {
|
||||||
return this.institucionTipoCarritoRepository
|
return this.institucionTipoCarritoRepository
|
||||||
.findOne({
|
.findOne({
|
||||||
id_institucion_tipo_carrito,
|
join: {
|
||||||
|
alias: 'itc',
|
||||||
|
innerJoinAndSelect: { i: 'itc.institucion', tc: 'itc.tipoCarrito' },
|
||||||
|
},
|
||||||
|
where: { id_institucion_tipo_carrito },
|
||||||
})
|
})
|
||||||
.then((institucionTipoCarrito) => {
|
.then((institucionTipoCarrito) => {
|
||||||
if (!institucionTipoCarrito)
|
if (!institucionTipoCarrito)
|
||||||
@ -106,11 +111,18 @@ export class InstitucionTipoCarritoService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
update(attrs: Partial<InstitucionTipoCarrito>) {
|
update(admin: Operador, attrs: Partial<InstitucionTipoCarrito>) {
|
||||||
return this.findInstitucionTipoCarritoById(
|
return this.findInstitucionTipoCarritoById(
|
||||||
attrs.id_institucion_tipo_carrito,
|
attrs.id_institucion_tipo_carrito,
|
||||||
)
|
)
|
||||||
.then((institucionTipoCarrito) => {
|
.then((institucionTipoCarrito) => {
|
||||||
|
if (
|
||||||
|
admin.institucion.id_institucion !=
|
||||||
|
institucionTipoCarrito.institucion.id_institucion
|
||||||
|
)
|
||||||
|
throw new ConflictException(
|
||||||
|
'No puedes actualizar la información de este tipo de carrito porque no le corresponde a tu institución.',
|
||||||
|
);
|
||||||
Object.assign(institucionTipoCarrito, attrs);
|
Object.assign(institucionTipoCarrito, attrs);
|
||||||
return this.institucionTipoCarritoRepository.save(
|
return this.institucionTipoCarritoRepository.save(
|
||||||
institucionTipoCarrito,
|
institucionTipoCarrito,
|
||||||
|
Loading…
Reference in New Issue
Block a user