From 4510999453f835fa6ef6d408660c7ae7e779c634 Mon Sep 17 00:00:00 2001 From: evenegas Date: Tue, 1 Jul 2025 17:13:51 -0600 Subject: [PATCH] correcion en las funciones de web service, descarga y movimientos --- src/excel/excel.service.ts | 9 +- src/movimiento/movimiento.service.ts | 4 + src/usuarios/usuarios.service.ts | 151 ++++++++++++++++++++++++--- 3 files changed, 147 insertions(+), 17 deletions(-) diff --git a/src/excel/excel.service.ts b/src/excel/excel.service.ts index 1a36a1b..e536350 100644 --- a/src/excel/excel.service.ts +++ b/src/excel/excel.service.ts @@ -466,6 +466,7 @@ export class ExcelService { }, servActivo: { CorreoStatus: 'Inactivo', // solo los que no tienen servicio activo + Correo: true, // solo los que tienen el servicio de correo activo } }, relations: [ @@ -531,6 +532,7 @@ export class ExcelService { }, servActivo: { PrestamosStatus: 'Inactivo', // solo los que no tienen servicio activo + Prestamos: true, // solo los que tienen el servicio de préstamos activo } }, relations: [ @@ -612,6 +614,7 @@ export class ExcelService { }, servActivo: { RedStatus: 'Inactivo', + Red: true, // solo los que tienen el servicio de red activo } }, relations: [ @@ -682,7 +685,7 @@ export class ExcelService { const header = [ 'num_cuenta', 'nombre', 'a_paterno', 'a_materno', - 'carreras', 'rfc', 'fecha_nacimiento', 'generacion' + 'carreras', 'fecha_nacimiento', 'generacion' ].join('\t') + '\n'; const rows = usuarios.map(u => { @@ -744,9 +747,7 @@ export class ExcelService { } else if (origen === 'SOLICITA' && servActivos.Prestamos) { servActivos.PrestamosStatus = timestamp; } else { - throw new BadRequestException( - `Origen ${origen} no válido o servicio no activo para el usuario con ID ${usuario.id_usuario}`, - ); + continue; } await this.servActivosRepo.save(servActivos); diff --git a/src/movimiento/movimiento.service.ts b/src/movimiento/movimiento.service.ts index 7bdacea..a55c978 100644 --- a/src/movimiento/movimiento.service.ts +++ b/src/movimiento/movimiento.service.ts @@ -112,6 +112,7 @@ export class MovimientoService { const field = statusFieldMap[origen as keyof typeof statusFieldMap]; + const origenField = FieldMap[origen as keyof typeof FieldMap]; if (!field) { const movimientos = await this.movRepo.find({ @@ -158,6 +159,7 @@ export class MovimientoService { status: 'SUCCESS', usuario: { servActivo: { + //[origenField]:true, [field]: 'Inactivo' }, }, @@ -170,6 +172,7 @@ export class MovimientoService { status: 'SUCCESS', usuario: { servActivo: { + //[origenField]:true, [field]: 'Inactivo' }, }, @@ -182,6 +185,7 @@ export class MovimientoService { status: 'SUCCESS', usuario: { servActivo: { + //[origenField]:true, [field]: 'Inactivo' }, }, diff --git a/src/usuarios/usuarios.service.ts b/src/usuarios/usuarios.service.ts index 65fe902..aa5e342 100644 --- a/src/usuarios/usuarios.service.ts +++ b/src/usuarios/usuarios.service.ts @@ -87,10 +87,13 @@ export class UsuariosService { } }; - mapServicio('Préstamo de equipo en CEDETEC', servActivo.ATStatus); - mapServicio('Red', servActivo.RedStatus); - mapServicio('Préstamo de equipo PC Puma', servActivo.PrestamosStatus); - mapServicio('Correo', servActivo.CorreoStatus); + + await mapServicio('Red', servActivo.RedStatus); + await mapServicio('Correo', servActivo.CorreoStatus); + await mapServicio('Préstamo de equipo PC Puma', servActivo.PrestamosStatus); + await mapServicio('Préstamo de equipo en CEDETEC', servActivo.ATStatus); + + if (resultado.length === 0) { return [{ @@ -100,6 +103,8 @@ export class UsuariosService { }]; } + console.log('Servicios encontrados:', resultado); + return resultado; } @@ -128,6 +133,7 @@ export class UsuariosService { 'CARGA MASIVA WEB SERVICE' ); + interface DatosEntrada { Nombre: string; ApellidoPaterno: string; @@ -246,9 +252,9 @@ export class UsuariosService { PrestamosStatus: 'Inactivo', CorreoStatus: 'Inactivo', usuario: savedUser, - AT: true, + AT: prof.numeroTrabajador !== '', Red: prof.numeroTrabajador !== '', - Prestamos: true, + Prestamos: prof.numeroTrabajador !== '', Correo: true }); @@ -264,18 +270,137 @@ export class UsuariosService { } else { let cambios = false; - if (prof.numeroTrabajador && existente.num_cuenta !== prof.numeroTrabajador) { - existente.num_cuenta = prof.numeroTrabajador; + + if (existente.nombre !== prof.nombre) { + existente.nombre = prof.nombre; + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + + + if (servActivo) { + servActivo.Red = true; + servActivo.AT = true; + servActivo.Prestamos = true; + + + servActivo.ATStatus = 'Inactivo'; + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.RedStatus = 'Inactivo'; + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } + cambios = true; + } + + if (existente.a_paterno !== prof.apellidoPaterno) { + existente.a_paterno = prof.apellidoPaterno; + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + + if (servActivo) { + servActivo.Red = true; + servActivo.AT = true; + servActivo.Prestamos = true; + + + servActivo.ATStatus = 'Inactivo'; + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.RedStatus = 'Inactivo'; + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } + + cambios = true; + } + + + if (existente.a_materno !== prof.apellidoMaterno) { + + existente.a_materno = prof.apellidoMaterno; + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + + if (servActivo) { + servActivo.Red = true; + servActivo.AT = true; + servActivo.Prestamos = true; + + + servActivo.ATStatus = 'Inactivo'; + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.RedStatus = 'Inactivo'; + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } + + cambios = true; + } + + if (existente.rfc !== prof.rfc) { + existente.rfc = prof.rfc; + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + + if (servActivo) { + servActivo.Red = true; + + servActivo.Prestamos = true; + + + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.RedStatus = 'Inactivo'; + + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } + cambios = true; + } + + if (existente.fecha_nacimiento !== prof.fechaNacimiento) { + existente.fecha_nacimiento = prof.fechaNacimiento; + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + + if (servActivo) { + + + servActivo.Prestamos = true; + servActivo.Correo = true; + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.CorreoStatus = 'Inactivo'; + + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } + cambios = true; + } + + if (prof.numeroTrabajador && existente.num_cuenta !== prof.numeroTrabajador) { + existente.num_cuenta = prof.numeroTrabajador; + + + const servActivo = await this.servActivosRepository.findOne({ where: { usuario: { id_usuario: existente.id_usuario } } }); + if (servActivo) { + servActivo.Red = true; + servActivo.AT = true; + servActivo.Correo = true; + servActivo.Prestamos = true; + + servActivo.CorreoStatus = 'Inactivo'; + servActivo.ATStatus = 'Inactivo'; + servActivo.PrestamosStatus = 'Inactivo'; + servActivo.RedStatus = 'Inactivo'; + await this.servActivosRepository.save(servActivo); + } else { + console.warn('No se encontró el servicio activo para el usuario:', existente); + } cambios = true; } - if (existente.nombre !== prof.nombre) { existente.nombre = prof.nombre; cambios = true; } - if (existente.a_paterno !== prof.apellidoPaterno) { existente.a_paterno = prof.apellidoPaterno; cambios = true; } - if (existente.a_materno !== prof.apellidoMaterno) { existente.a_materno = prof.apellidoMaterno; cambios = true; } - if (existente.rfc !== prof.rfc) { existente.rfc = prof.rfc; cambios = true; } - if (existente.fecha_nacimiento !== prof.fechaNacimiento) { existente.fecha_nacimiento = prof.fechaNacimiento; cambios = true; } if (cambios) { + existente.movimiento = mov; await this.usuarioRepository.save(existente); + actualizados++; } }