marca y modelo endpoints restringidos a usuario

This commit is contained in:
xXpuma99Xx
2022-08-01 01:40:54 -05:00
parent 20d8081c84
commit aaca77af2a
10 changed files with 81 additions and 19 deletions
+18 -2
View File
@@ -1,4 +1,13 @@
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
import {
Body,
ConflictException,
Controller,
Get,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import {
ApiBearerAuth,
@@ -9,6 +18,7 @@ import {
} from '@nestjs/swagger';
import { Serealize } from '../interceptors/serialize.interceptor';
import { ModeloService } from './modelo.service';
import { Operador } from 'src/operador/entity/operador.entity';
import { CreateModeloDto } from './dto/input/create.dto';
import { ModeloDto } from './dto/input/modelo.dto';
import { ModeloOutputDto } from './dto/output/modelo.dto';
@@ -40,7 +50,13 @@ export class ModeloController {
description: 'Todas las variables son obligatorias.',
examples: { ejemplo: { value: { modelo: '', tipo: '' } } },
})
create(@Body() body: CreateModeloDto) {
create(@Request() req, @Body() body: CreateModeloDto) {
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.modeloService.create(body.modelo, body.tipo);
}
}