diff --git a/src/excel/excel.controller.ts b/src/excel/excel.controller.ts index 554d230..8b759f5 100644 --- a/src/excel/excel.controller.ts +++ b/src/excel/excel.controller.ts @@ -38,34 +38,27 @@ export class ExcelController { console.log('Alta de usuario:', alta); await this.movimientoService.updateStatus(alta.movId, 'SUCCESS') - await this.mailService.sendMail({ - to: req.user.email, // Asegúrate de que el usuario tenga un email - subject: 'Carga de datos exitosa', - text: "La carga de datos se ha realizado con éxito.", - html: `

La carga de datos se ha realizado con éxito ${alta}

`, - }); - await this.excelService.enviarInforme("LOAD","Carga Individual de datos en Servicios PCpuma", `Se ha hecho una carga individual en el sistema por el usuario ${req.user.email}`) if(alta.at){ await this.excelService.enviarInforme('AT',"Carga Individual de datos en Servicios PCpuma", - `Se ha hecho una carga individual en el sistema`) + `Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`) } if(alta.red){ await this.excelService.enviarInforme('RED',"Carga Individual de datos en Servicios PCpuma", - `Se ha hecho una carga individual en el sistema`) + `Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`) } if(alta.solicita){ await this.excelService.enviarInforme('SOLICITA',"Carga Individual de datos en Servicios PCpuma", - `Se ha hecho una carga individual en el sistema` ) + `Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}` ) } if(alta.correo){ await this.excelService.enviarInforme('CORREO',"Carga Individual de datos en Servicios PCpuma", - `Se ha hecho una carga individual en el sistema`) + `Se ha hecho una carga individual en el sistema de ${usuario.tipo_usuario}`) } } @@ -138,9 +131,13 @@ export class ExcelController { to: req.user.email, // Asegúrate de que el usuario tenga un email subject: 'Carga de datos exitosa', text: "La carga de datos se ha realizado con éxito.", - html: `

La carga de datos se ha realizado con éxito. Se han insertado ${result.inserted} registros.

-

Errores encontrados:

- `, + html: + `

La carga de datos se ha realizado con éxito. Se han insertado ${result.inserted} registros.

+

Usuarios At: ${result.conteoTiposAt}

+

Usuarios Red: ${result.conteoTiposRed}

+

Usuarios Solicita: ${result.conteoTiposSolicita}

+

Usuarios Correo: ${result.conteoTiposCorreo}

+ `, }); // await this.excelService.enviarCargaMasiva(); diff --git a/src/excel/excel.service.ts b/src/excel/excel.service.ts index d29c9f3..39e1951 100644 --- a/src/excel/excel.service.ts +++ b/src/excel/excel.service.ts @@ -831,18 +831,23 @@ export class ExcelService { async enviarInforme(origen:string, subject:string ,text:string, html:string = "" ):Promise{ - const user = await this.usuariosDelSistemaRepo.find({where:{origen:{origen}}}) - - user.forEach(async(u)=>{ + + try{ + const user = await this.usuariosDelSistemaRepo.find({where:{origen:{origen}}}) + user.forEach(async(u)=>{ await this.mailService.sendMail({ to: u.correo ?? '', subject, text, html, - }); + }); + }) - }) + }catch(error){ + throw new BadRequestException('No se encontraron usuarios para enviar correo o no se pudo enviar el correo'); + } + }