nuevo registro
This commit is contained in:
parent
9b5eb7ecda
commit
7f7dfbe9c1
@ -34,7 +34,6 @@ export class InstitucionUsuarioService {
|
|||||||
findByUsuarioInstitucionCarrera(
|
findByUsuarioInstitucionCarrera(
|
||||||
usuario: Usuario,
|
usuario: Usuario,
|
||||||
institucionCarrera: InstitucionCarrera,
|
institucionCarrera: InstitucionCarrera,
|
||||||
campo: string,
|
|
||||||
) {
|
) {
|
||||||
return this.repository
|
return this.repository
|
||||||
.findOne({
|
.findOne({
|
||||||
|
@ -1,12 +1,29 @@
|
|||||||
import { IsEmail, IsInt, IsPhoneNumber } from 'class-validator';
|
import {
|
||||||
|
IsEmail,
|
||||||
|
IsInt,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsPhoneNumber,
|
||||||
|
IsString,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class RegistrarUsuarioInputDto {
|
export class RegistrarUsuarioInputDto {
|
||||||
|
@IsEmail()
|
||||||
|
correo: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
id_institucion_usuario: number;
|
@IsOptional()
|
||||||
|
id_institucion_carrera: number;
|
||||||
|
|
||||||
@IsPhoneNumber('MX')
|
@IsPhoneNumber('MX')
|
||||||
telefono: string;
|
telefono: string;
|
||||||
|
|
||||||
@IsEmail()
|
@IsString()
|
||||||
correo: string;
|
@IsNotEmpty()
|
||||||
|
usuario: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsOptional()
|
||||||
|
rfc?: string;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,10 @@ import { Recaptcha } from '@nestlab/google-recaptcha';
|
|||||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||||
import { UsuarioService } from './usuario.service';
|
import { UsuarioService } from './usuario.service';
|
||||||
import { Operador } from '../operador/entity/operador.entity';
|
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 { RegistrarUsuarioInputDto } from './dto/input/registrar.dto';
|
||||||
import { UpdateUsuarioInputDto } from './dto/input/update.dto';
|
import { UpdateUsuarioInputDto } from './dto/input/update.dto';
|
||||||
import { UsuarioInputDto } from './dto/input/usuario.dto';
|
import { UsuarioInputDto } from './dto/input/usuario.dto';
|
||||||
import { UsuariosInputDto } from './dto/input/usuarios.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 { UsuarioOutputDto } from './dto/output/usuario.dto';
|
||||||
import { UsuariosOutputDto } from './dto/output/usuarios.dto';
|
import { UsuariosOutputDto } from './dto/output/usuarios.dto';
|
||||||
|
|
||||||
@ -36,49 +33,6 @@ import { UsuariosOutputDto } from './dto/output/usuarios.dto';
|
|||||||
export class UsuarioController {
|
export class UsuarioController {
|
||||||
constructor(private usuarioService: UsuarioService) {}
|
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')
|
@Post('registrar')
|
||||||
@Recaptcha()
|
@Recaptcha()
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
@ -93,9 +47,11 @@ export class UsuarioController {
|
|||||||
})
|
})
|
||||||
registrar(@Body() body: RegistrarUsuarioInputDto) {
|
registrar(@Body() body: RegistrarUsuarioInputDto) {
|
||||||
return this.usuarioService.registrar(
|
return this.usuarioService.registrar(
|
||||||
body.id_institucion_usuario,
|
body.id_institucion_carrera,
|
||||||
|
body.usuario,
|
||||||
body.correo,
|
body.correo,
|
||||||
body.telefono,
|
body.telefono,
|
||||||
|
body.rfc,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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: {
|
async findAll(filtros: {
|
||||||
pagina: string;
|
pagina: string;
|
||||||
id_carrera?: string;
|
id_carrera?: string;
|
||||||
@ -180,6 +133,7 @@ export class UsuarioService {
|
|||||||
validarNoExiste = true,
|
validarNoExiste = true,
|
||||||
password = false,
|
password = false,
|
||||||
institucionesActivas = false,
|
institucionesActivas = false,
|
||||||
|
rfc?: string,
|
||||||
) {
|
) {
|
||||||
const query = this.repository
|
const query = this.repository
|
||||||
.createQueryBuilder('u')
|
.createQueryBuilder('u')
|
||||||
@ -192,6 +146,7 @@ export class UsuarioService {
|
|||||||
.where('usuario = :usuario', { usuario });
|
.where('usuario = :usuario', { usuario });
|
||||||
|
|
||||||
if (institucionesActivas) query.andWhere('is.activo = 1');
|
if (institucionesActivas) query.andWhere('is.activo = 1');
|
||||||
|
if (rfc) query.andWhere('rfc = :rfc', { rfc });
|
||||||
return query.getOne().then((usuario) => {
|
return query.getOne().then((usuario) => {
|
||||||
if (validarNoExiste && (!usuario || (password && !usuario.password)))
|
if (validarNoExiste && (!usuario || (password && !usuario.password)))
|
||||||
throw new NotFoundException('No existe este usuario.');
|
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();
|
const password = this.bcryptService.generarPassword();
|
||||||
let message: string;
|
let message: string;
|
||||||
|
|
||||||
return this.institucionUsuarioService
|
return this.findByUsuario(usuario, false, false, false, rfc)
|
||||||
.findById(id_institucion_usuario)
|
.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) => {
|
.then((institucionUsuario) => {
|
||||||
const institucion = institucionUsuario.institucionCarrera.institucion;
|
const institucion = institucionUsuario.institucionCarrera.institucion;
|
||||||
const usuario = institucionUsuario.usuario;
|
const usuario = institucionUsuario.usuario;
|
||||||
|
|
||||||
if (usuario.password)
|
|
||||||
throw new ConflictException(
|
|
||||||
'Ya fue registrado este número de cuenta.',
|
|
||||||
);
|
|
||||||
if (usuario.correo && correo != usuario.correo)
|
if (usuario.correo && correo != usuario.correo)
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
'El correo ingresado no concuerda con el ingresado a escolares.',
|
'El correo ingresado no concuerda con el ingresado a escolares.',
|
||||||
);
|
);
|
||||||
if (!institucion.dominio)
|
if (!institucion.dominio)
|
||||||
message =
|
message =
|
||||||
'Se creó correctamente tu cuenta, ingresa a tu correo y consulta tu contraseña para acceder a este servicio.';
|
'Se creó correctamente tu cuenta, ingresa a tu correo registrado en escolares y consulta tu contraseña para acceder a este servicio.';
|
||||||
else
|
else {
|
||||||
|
if (!correo.includes(institucion.dominio))
|
||||||
|
throw new ConflictException(
|
||||||
|
'Verificar sus datos, cualquier duda asistir al módulo PC PUMA.',
|
||||||
|
);
|
||||||
message =
|
message =
|
||||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
||||||
|
}
|
||||||
usuario.correo = correo;
|
usuario.correo = correo;
|
||||||
usuario.telefono = telefono;
|
usuario.telefono = telefono;
|
||||||
usuario.password = this.bcryptService.encriptar(password);
|
usuario.password = this.bcryptService.encriptar(password);
|
||||||
|
Loading…
Reference in New Issue
Block a user