From 7f7dfbe9c1b06cc9a9ed8193b88203ee235d9cd6 Mon Sep 17 00:00:00 2001 From: lemuel Date: Mon, 22 Aug 2022 13:43:59 -0500 Subject: [PATCH] nuevo registro --- .../institucion-usuario.service.ts | 1 - src/usuario/dto/input/registrar.dto.ts | 25 +++++- src/usuario/usuario.controller.ts | 50 +---------- src/usuario/usuario.service.ts | 86 +++++++------------ 4 files changed, 54 insertions(+), 108 deletions(-) diff --git a/src/institucion-usuario/institucion-usuario.service.ts b/src/institucion-usuario/institucion-usuario.service.ts index 372d292..92a198f 100644 --- a/src/institucion-usuario/institucion-usuario.service.ts +++ b/src/institucion-usuario/institucion-usuario.service.ts @@ -34,7 +34,6 @@ export class InstitucionUsuarioService { findByUsuarioInstitucionCarrera( usuario: Usuario, institucionCarrera: InstitucionCarrera, - campo: string, ) { return this.repository .findOne({ diff --git a/src/usuario/dto/input/registrar.dto.ts b/src/usuario/dto/input/registrar.dto.ts index c103ee9..df1b3fb 100644 --- a/src/usuario/dto/input/registrar.dto.ts +++ b/src/usuario/dto/input/registrar.dto.ts @@ -1,12 +1,29 @@ -import { IsEmail, IsInt, IsPhoneNumber } from 'class-validator'; +import { + IsEmail, + IsInt, + IsNotEmpty, + IsOptional, + IsPhoneNumber, + IsString, +} from 'class-validator'; export class RegistrarUsuarioInputDto { + @IsEmail() + correo: string; + @IsInt() - id_institucion_usuario: number; + @IsOptional() + id_institucion_carrera: number; @IsPhoneNumber('MX') telefono: string; - @IsEmail() - correo: string; + @IsString() + @IsNotEmpty() + usuario: string; + + @IsString() + @IsNotEmpty() + @IsOptional() + rfc?: string; } diff --git a/src/usuario/usuario.controller.ts b/src/usuario/usuario.controller.ts index 7378fff..e554d5c 100644 --- a/src/usuario/usuario.controller.ts +++ b/src/usuario/usuario.controller.ts @@ -21,13 +21,10 @@ import { Recaptcha } from '@nestlab/google-recaptcha'; import { Serealize } from '../interceptors/serialize.interceptor'; import { UsuarioService } from './usuario.service'; import { Operador } from '../operador/entity/operador.entity'; -import { DgaeInputDto } from './dto/input/dgae.dto'; -import { DgpInputDto } from './dto/input/dgp.dto'; import { RegistrarUsuarioInputDto } from './dto/input/registrar.dto'; import { UpdateUsuarioInputDto } from './dto/input/update.dto'; import { UsuarioInputDto } from './dto/input/usuario.dto'; import { UsuariosInputDto } from './dto/input/usuarios.dto'; -import { UsuarioInstitucionCarreraOutputDto } from '../institucion-usuario/dto/output/usuario-institucion-carrera.dto'; import { UsuarioOutputDto } from './dto/output/usuario.dto'; import { UsuariosOutputDto } from './dto/output/usuarios.dto'; @@ -36,49 +33,6 @@ import { UsuariosOutputDto } from './dto/output/usuarios.dto'; export class UsuarioController { constructor(private usuarioService: UsuarioService) {} - @Serealize(UsuarioInstitucionCarreraOutputDto) - @Recaptcha() - @Get('dgae') - @ApiOperation({ - description: 'Endpoint que retorna información de dgae de un alumno.', - }) - @ApiQuery({ - description: 'Número de cuenta del alumno.', - name: 'usuario', - type: 'string', - }) - @ApiQuery({ - description: 'Id de la carrera institución a la que pertenece el alumno.', - name: 'id_institucion_carrera', - type: 'string', - }) - dgae(@Query() query: DgaeInputDto) { - return this.usuarioService.DGAE( - query.usuario, - parseInt(query.id_institucion_carrera), - ); - } - - @Serealize(UsuarioInstitucionCarreraOutputDto) - @Recaptcha() - @Get('dgp') - @ApiOperation({ - description: 'Endpoint que retorna información de dgp de un profesor.', - }) - @ApiQuery({ - description: 'Número de cuenta del profesor.', - name: 'usuario', - type: 'string', - }) - @ApiQuery({ description: 'RFC del profesor.', name: 'rfc', type: 'string' }) - dgp(@Query() query: DgpInputDto) { - return this.usuarioService.DGP( - parseInt(query.id_institucion), - query.usuario, - query.rfc, - ); - } - @Post('registrar') @Recaptcha() @ApiOperation({ @@ -93,9 +47,11 @@ export class UsuarioController { }) registrar(@Body() body: RegistrarUsuarioInputDto) { return this.usuarioService.registrar( - body.id_institucion_usuario, + body.id_institucion_carrera, + body.usuario, body.correo, body.telefono, + body.rfc, ); } diff --git a/src/usuario/usuario.service.ts b/src/usuario/usuario.service.ts index fdef885..18a297c 100644 --- a/src/usuario/usuario.service.ts +++ b/src/usuario/usuario.service.ts @@ -50,53 +50,6 @@ export class UsuarioService { ); } - async DGAE(usuario: string, id_institucion_carrera: number) { - const institucionCarrera = await this.institucionCarreraService.findById( - id_institucion_carrera, - ); - - return this.findByUsuario(usuario, false).then(async (existeUsuario) => { - if (!existeUsuario || existeUsuario.password) - throw new ConflictException( - 'Verificar sus datos, cualquier duda asistir al módulo PC PUMA.', - ); - return this.institucionUsuarioService.findByUsuarioInstitucionCarrera( - existeUsuario, - institucionCarrera, - 'cuenta', - ); - }); - } - - async DGP(id_institucion: number, usuario: string, rfc: string) { - const institucionCarrera = - await this.institucionCarreraService.findByIdInstitucionIdCarrera( - id_institucion, - 1, - ); - - return this.repository - .createQueryBuilder('u') - .innerJoinAndSelect('u.instituciones', 'is') - .innerJoinAndSelect('u.tipoUsuario', 'tu') - .innerJoinAndSelect('is.institucionCarrera', 'ic') - .innerJoinAndSelect('ic.carrera', 'c') - .innerJoinAndSelect('ic.institucion', 'i') - .where('usuario = :usuario && rfc = :rfc', { usuario, rfc }) - .getOne() - .then((usuario) => { - if (!usuario || usuario.password) - throw new NotFoundException( - 'Verificar sus datos, cualquier duda asistir al módulo PC PUMA.', - ); - return this.institucionUsuarioService.findByUsuarioInstitucionCarrera( - usuario, - institucionCarrera, - 'trabajador', - ); - }); - } - async findAll(filtros: { pagina: string; id_carrera?: string; @@ -180,6 +133,7 @@ export class UsuarioService { validarNoExiste = true, password = false, institucionesActivas = false, + rfc?: string, ) { const query = this.repository .createQueryBuilder('u') @@ -192,6 +146,7 @@ export class UsuarioService { .where('usuario = :usuario', { usuario }); if (institucionesActivas) query.andWhere('is.activo = 1'); + if (rfc) query.andWhere('rfc = :rfc', { rfc }); return query.getOne().then((usuario) => { if (validarNoExiste && (!usuario || (password && !usuario.password))) throw new NotFoundException('No existe este usuario.'); @@ -219,30 +174,49 @@ export class UsuarioService { })); } - registrar(id_institucion_usuario: number, correo: string, telefono: string) { + async registrar( + id_institucion_carrera: number, + usuario: string, + correo: string, + telefono: string, + rfc = '', + ) { + const institucionCarrera = await this.institucionCarreraService.findById( + id_institucion_carrera, + ); const password = this.bcryptService.generarPassword(); let message: string; - return this.institucionUsuarioService - .findById(id_institucion_usuario) + return this.findByUsuario(usuario, false, false, false, rfc) + .then(async (existeUsuario) => { + if (!existeUsuario || existeUsuario.password) + throw new ConflictException( + 'Verificar sus datos, cualquier duda asistir al módulo PC PUMA.', + ); + return this.institucionUsuarioService.findByUsuarioInstitucionCarrera( + existeUsuario, + institucionCarrera, + ); + }) .then((institucionUsuario) => { const institucion = institucionUsuario.institucionCarrera.institucion; const usuario = institucionUsuario.usuario; - if (usuario.password) - throw new ConflictException( - 'Ya fue registrado este número de cuenta.', - ); if (usuario.correo && correo != usuario.correo) throw new ConflictException( 'El correo ingresado no concuerda con el ingresado a escolares.', ); if (!institucion.dominio) message = - 'Se creó correctamente tu cuenta, ingresa a tu correo y consulta tu contraseña para acceder a este servicio.'; - else + 'Se creó correctamente tu cuenta, ingresa a tu correo registrado en escolares y consulta tu contraseña para acceder a este servicio.'; + else { + if (!correo.includes(institucion.dominio)) + throw new ConflictException( + 'Verificar sus datos, cualquier duda asistir al módulo PC PUMA.', + ); message = 'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.'; + } usuario.correo = correo; usuario.telefono = telefono; usuario.password = this.bcryptService.encriptar(password);