modulo tipo usuario final
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Equipo } from '../../equipo/entity/equipo.entity';
|
||||
import { Motivo } from '../../motivo/entity/motivo.entity';
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ export class TipoUsuario {
|
||||
@Column({ type: String, nullable: false, length: 20 })
|
||||
tipo_usuario: string;
|
||||
|
||||
@OneToMany(() => Usuario, (usuario) => usuario.tipoUsuario)
|
||||
usuarios: Usuario[];
|
||||
|
||||
@OneToMany(() => Operador, (operador) => operador.tipoUsuario)
|
||||
operadores: Operador[];
|
||||
|
||||
@OneToMany(() => Usuario, (usuario) => usuario.tipoUsuario)
|
||||
usuarios: Usuario[];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { TipoUsuarioService } from './tipo-usuario.service';
|
||||
@@ -11,9 +12,10 @@ export class TipoUsuarioController {
|
||||
constructor(private tipoUsuarioService: TipoUsuarioService) {}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que crea un nuevo tipo de usuario.' })
|
||||
@ApiBody({
|
||||
description: 'Es obligatoria mandar el campo tipo_usuario.',
|
||||
description: 'Es obligatorio mandar el campo tipo_usuario.',
|
||||
examples: { ejemplo: { value: { tipo_usuario: '' } } },
|
||||
})
|
||||
create(@Body() body: TipoUsuarioUpdateDto) {
|
||||
@@ -22,6 +24,7 @@ export class TipoUsuarioController {
|
||||
|
||||
@Serealize(TipoUsuarioOutputDto)
|
||||
@Get()
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description: 'Endpoint que retorna todos los tipos de usuario.',
|
||||
})
|
||||
|
||||
@@ -21,7 +21,9 @@ export class TipoUsuarioService {
|
||||
throw new ConflictException('Ya existe este tipo usuario');
|
||||
return this.repository.save(this.repository.create({ tipo_usuario }));
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente el tipo usuario.' }));
|
||||
.then((_) => ({
|
||||
message: 'Se creó correctamente un nuevo tipo de usuario.',
|
||||
}));
|
||||
}
|
||||
|
||||
findAll() {
|
||||
@@ -31,7 +33,7 @@ export class TipoUsuarioService {
|
||||
findById(id_tipo_usuario: number) {
|
||||
return this.repository.findOne({ id_tipo_usuario }).then((tipoUsuario) => {
|
||||
if (!tipoUsuario)
|
||||
throw new NotFoundException('No existe este tipo usuairo');
|
||||
throw new NotFoundException('No existe este tipo usuario');
|
||||
return tipoUsuario;
|
||||
});
|
||||
}
|
||||
@@ -39,7 +41,7 @@ export class TipoUsuarioService {
|
||||
findByTipoUsuario(tipo_usuario: string, validarNoExiste = true) {
|
||||
return this.repository.findOne({ tipo_usuario }).then((tipoUsuario) => {
|
||||
if (validarNoExiste && !tipoUsuario)
|
||||
throw new NotFoundException('No existe este tipo usuairo');
|
||||
throw new NotFoundException('No existe este tipo usuario');
|
||||
return tipoUsuario;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user