tipo usaurio endpoints restringidos a usuario
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
ConflictException,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Request,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { TipoUsuarioService } from './tipo-usuario.service';
|
||||
import { Operador } from 'src/operador/entity/operador.entity';
|
||||
import { CreateTipoUsuarioDto } from './dto/input/create.dto';
|
||||
import { TipoUsuarioOutputDto } from './dto/output/tipo-usuario.dto';
|
||||
|
||||
@@ -19,7 +28,13 @@ export class TipoUsuarioController {
|
||||
description: 'Es obligatorio mandar el campo tipo_usuario.',
|
||||
examples: { ejemplo: { value: { tipo_usuario: '' } } },
|
||||
})
|
||||
create(@Body() body: CreateTipoUsuarioDto) {
|
||||
create(@Request() req, @Body() body: CreateTipoUsuarioDto) {
|
||||
const superAdmin: Operador = req.user.operador;
|
||||
|
||||
if (!superAdmin || superAdmin.tipoUsuario.id_tipo_usuario != 2)
|
||||
throw new ConflictException(
|
||||
'No tienes permisos para realizar esta acción.',
|
||||
);
|
||||
return this.tipoUsuarioService.create(body.tipo_usuario);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user