modulo operador final
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity';
|
||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@@ -29,18 +29,22 @@ export class OperadorService {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const tipoUsuario = await this.tipoUsuarioService.findById(id_tipo_usuario);
|
||||
|
||||
if (tipoUsuario.id_tipo_usuario < 3 || tipoUsuario.id_tipo_usuario > 4)
|
||||
throw new ConflictException(
|
||||
'No se puede asignar un tipo de usuario distinto a admin y operador',
|
||||
);
|
||||
return this.findAdmin(operador, false)
|
||||
.then((existeAdmin) => {
|
||||
if (existeAdmin)
|
||||
throw new ConflictException(
|
||||
'Ya existe un admin con ese nombre, intente de nuevo.',
|
||||
'Ya existe un admin con ese nombre, intenta de nuevo con otro.',
|
||||
);
|
||||
return this.findByOperador(institucion, operador, false);
|
||||
})
|
||||
.then(async (existeOperador) => {
|
||||
if (existeOperador)
|
||||
throw new ConflictException(
|
||||
'Ya existe un operador con ese nombre, intente de nuevo.',
|
||||
'Ya existe un operador en esta institución con ese nombre, intenta de nuevo con otro.',
|
||||
);
|
||||
password = this.bcryptService.encriptar(password);
|
||||
return this.repository.save(
|
||||
@@ -52,7 +56,9 @@ export class OperadorService {
|
||||
}),
|
||||
);
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente al operador.' }));
|
||||
.then((_) => ({
|
||||
message: `Se creó correctamente un nuevo ${tipoUsuario.tipo_usuario.toLowerCase()}.`,
|
||||
}));
|
||||
}
|
||||
|
||||
findAdmin(admin: string, validarNoExiste = true) {
|
||||
@@ -143,7 +149,7 @@ export class OperadorService {
|
||||
return this.repository.save(operador);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se actualizo correctamente la información del operador.',
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class TipoUsuarioUpdateDto {
|
||||
export class CreateTipoUsuarioDto {
|
||||
@IsString()
|
||||
tipo_usuario: string;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { TipoUsuarioService } from './tipo-usuario.service';
|
||||
import { TipoUsuarioUpdateDto } from './dto/input/tipo-usuario-update.dto';
|
||||
import { CreateTipoUsuarioDto } from './dto/input/create.dto';
|
||||
import { TipoUsuarioOutputDto } from './dto/output/tipo-usuario.dto';
|
||||
|
||||
@Controller('tipo-usuario')
|
||||
@@ -18,7 +18,7 @@ export class TipoUsuarioController {
|
||||
description: 'Es obligatorio mandar el campo tipo_usuario.',
|
||||
examples: { ejemplo: { value: { tipo_usuario: '' } } },
|
||||
})
|
||||
create(@Body() body: TipoUsuarioUpdateDto) {
|
||||
create(@Body() body: CreateTipoUsuarioDto) {
|
||||
return this.tipoUsuarioService.create(body.tipo_usuario);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user