vulnerabilyties fixed
This commit is contained in:
Generated
+604
-96
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -28,14 +28,14 @@
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"csv-parser": "^3.2.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"exceljs": "^4.4.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"mysql2": "^3.13.0",
|
||||
"nodemailer": "^6.10.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.21",
|
||||
"xlsx": "^0.18.5"
|
||||
"typeorm": "^0.3.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
||||
+30
-18
@@ -1,35 +1,47 @@
|
||||
import * as fs from 'fs';
|
||||
import * as XLSX from 'xlsx';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ExcelService {
|
||||
readEmailsFromExcel(filePath: string): string[] {
|
||||
console.log(` Verificando archivo en: ${filePath}`);
|
||||
async readEmailsFromExcel(filePath: string): Promise<string[]> {
|
||||
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.error(' Archivo Excel NO encontrado');
|
||||
|
||||
throw new Error('Archivo Excel no encontrado');
|
||||
} else {
|
||||
console.log('Archivo Excel encontrado');
|
||||
}
|
||||
|
||||
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.readFile(filePath); // 🔹 `await` para leer el archivo correctamente
|
||||
|
||||
const worksheet = workbook.getWorksheet(1); // Obtiene la primera hoja
|
||||
if (!worksheet) {
|
||||
throw new Error(' No se encontró ninguna hoja en el archivo.');
|
||||
}
|
||||
|
||||
const workbook = XLSX.readFile(filePath);
|
||||
const sheetName = workbook.SheetNames[0];
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
const jsonData: any[] = [];
|
||||
|
||||
const jsonData = XLSX.utils.sheet_to_json(sheet);
|
||||
|
||||
console.log(`Datos extraídos:`, jsonData);
|
||||
// 🔹 Iterar sobre las filas y extraer datos
|
||||
worksheet.eachRow((row, rowNumber) => {
|
||||
if (rowNumber === 1) return; // Ignorar encabezado
|
||||
|
||||
// Extraer correos de la columna "Correo"
|
||||
const rowData = {
|
||||
Correo: row.getCell(1).value, // Ajusta el índice según tu archivo
|
||||
};
|
||||
|
||||
jsonData.push(rowData);
|
||||
});
|
||||
|
||||
console.log(` Datos extraídos:`, jsonData);
|
||||
|
||||
// 🔹 Extraer correos de la columna "Correo"
|
||||
const emails = jsonData
|
||||
.map((row: any) => row['Correo'])
|
||||
.filter(email => email);
|
||||
.map(row => row.Correo)
|
||||
.filter(email => typeof email === 'string');
|
||||
|
||||
console.log(` Correos extraídos:`, emails);
|
||||
console.log(` Correos extraídos:`, emails);
|
||||
|
||||
return emails;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class MailController {
|
||||
const emails=this.excelService.readEmailsFromExcel('./src/excel_Usuarios/usuarios_fake.xlsx');
|
||||
let fechaActual: Date = new Date();
|
||||
|
||||
for (const email of emails) {
|
||||
for (const email of await emails) {
|
||||
try {
|
||||
await this.mailService.sendMail(email, "subject", "text", fechaActual);
|
||||
console.log(`📧 Enviado a: ${email}`);
|
||||
|
||||
Reference in New Issue
Block a user