institucion tipo entrada 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,7 @@ import {
|
||||
} from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { InstitucionTipoEntradaService } from './institucion-tipo-entrada.service';
|
||||
import { Operador } from 'src/operador/entity/operador.entity';
|
||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||
import { CreateInstitucionTipoEntradaDto } from './dto/input/create.dto';
|
||||
import { UpdateInstitucionTipoEntradaDto } from './dto/input/update.dto';
|
||||
@@ -37,7 +40,11 @@ export class InstitucionTipoEntradaController {
|
||||
description: 'Es obligatorio mandar la variable tipo_entrada.',
|
||||
examples: { ejemplo: { value: { tipo_entrada: '' } } },
|
||||
})
|
||||
create(@Body() body: CreateInstitucionTipoEntradaDto) {
|
||||
create(@Request() req, @Body() body: CreateInstitucionTipoEntradaDto) {
|
||||
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.tipoEntradaService.create(body.tipo_entrada);
|
||||
}
|
||||
|
||||
@@ -104,7 +111,11 @@ export class InstitucionTipoEntradaController {
|
||||
ejemplo: { value: { id_institucion_tipo_entrada: 130, mostrar: true } },
|
||||
},
|
||||
})
|
||||
update(@Body() body: UpdateInstitucionTipoEntradaDto) {
|
||||
return this.tipoEntradaService.update(body);
|
||||
update(@Request() req, @Body() body: UpdateInstitucionTipoEntradaDto) {
|
||||
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.tipoEntradaService.update(admin, body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity';
|
||||
import { Operador } from 'src/operador/entity/operador.entity';
|
||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@@ -71,7 +72,11 @@ export class InstitucionTipoEntradaService {
|
||||
findById(id_institucion_tipo_entrada: number) {
|
||||
return this.institucionTipoEntradaRepository
|
||||
.findOne({
|
||||
id_institucion_tipo_entrada,
|
||||
join: {
|
||||
alias: 'ite',
|
||||
innerJoinAndSelect: { i: 'ite.institucion', te: 'ite.tipoEntrada' },
|
||||
},
|
||||
where: { id_institucion_tipo_entrada },
|
||||
})
|
||||
.then((institucionTipoEntrada) => {
|
||||
if (!institucionTipoEntrada)
|
||||
@@ -102,9 +107,16 @@ export class InstitucionTipoEntradaService {
|
||||
});
|
||||
}
|
||||
|
||||
update(attrs: Partial<InstitucionTipoEntrada>) {
|
||||
update(admin: Operador, attrs: Partial<InstitucionTipoEntrada>) {
|
||||
return this.findById(attrs.id_institucion_tipo_entrada)
|
||||
.then((institucionTipoEntrada) => {
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionTipoEntrada.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(institucionTipoEntrada, attrs);
|
||||
return this.institucionTipoEntradaRepository.save(
|
||||
institucionTipoEntrada,
|
||||
|
||||
Reference in New Issue
Block a user