From 3abd381f2ea044403847fe61c0d5cd84b7c5c8af Mon Sep 17 00:00:00 2001 From: "Denise D." Date: Tue, 28 Jul 2026 14:36:38 +0200 Subject: [PATCH] Removal of the function that creates the accounts --- file.js | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/file.js b/file.js index 073b1e6..37c524f 100644 --- a/file.js +++ b/file.js @@ -1,8 +1,6 @@ const ExcelJS = require('exceljs'); const { PDFParse } = require('pdf-parse'); const { PDFDocument } = require('pdf-lib'); -const readline = require('node:readline/promises'); -const { stdin: input, stdout: output } = require('node:process'); const fs = require('fs'); const os = require('os'); const path = require('path'); @@ -51,13 +49,13 @@ function escapeSoql(str) { // the pdf files contain the identifying ids of the users such as 'Codice Fiscale' (CF) and we use them to attach // the page/pages to the specific account that has that id. If CFs are not available we search based on the // name an lastname of the user -async function attachPdfToAccount(sfdc, temFiles) { +async function attachPdfToAccount(sfdc, tempFiles) { let parser; try { let contentVersion; - for (let i = 0; i < temFiles.length; i++) { + for (let i = 0; i < tempFiles.length; i++) { // 1. Read the local PDF file and convert it to Base64 - const pdfBuffer = fs.readFileSync(temFiles[i]); + const pdfBuffer = fs.readFileSync(tempFiles[i]); const base64Pdf = pdfBuffer.toString('base64'); parser = new PDFParse({ data: pdfBuffer }); try { @@ -238,7 +236,6 @@ async function splitPDF(numRows, inputFile, tempFiles) { let parser; try { - // 1. we use pdfParse to read and extract the content of a pdf file const existingPdfBytes = fs.readFileSync(inputFile); parser = new PDFParse({ data: existingPdfBytes }); @@ -264,12 +261,10 @@ async function splitPDF(numRows, inputFile, tempFiles) { } else { for (let i = 0; i < pagesNumber; i++) { - /*console.log(`--- PAGE ${i + 1} ---`); - console.log(result.pages[i].text); - console.log("\n");*/ await processPage(srcPdf, i, tempFiles); // Pass 0-based index i } } + return tempFiles; } catch (error) { console.error(`Error processing the pdf file: `, error); @@ -301,35 +296,13 @@ async function main() { process.exit(1); } - const tempFilePath = []; // contains the temp files - let resultExcel; + const tempFilePath = []; // contains the temporary files + let resultExcel, resultPdf; try { resultExcel = await splitExcelFile(excelFile); - await splitPDF(resultExcel.numRows, pdfFile, tempFilePath); - const rl = readline.createInterface({ input, output }); - let reply = ''; - - try { - while(!reply) { - const response = await rl.question('Do you want to create accounts or upload pages (accounts/pages)? '); - reply = response.trim(); - - if (!reply) { - console.log('Please try again!'); - } - } - - if (reply === 'accounts') { - await uploadUserAccount(resultExcel.data); - } - else if (reply === 'pages') { - await initializeSalesforceConnection(); - await attachPdfToAccount(sfdc, tempFilePath); - } - } - finally { - rl.close(); - } + resultPdf = await splitPDF(resultExcel.numRows, pdfFile, tempFilePath); + await initializeSalesforceConnection(); + await attachPdfToAccount(sfdc, resultPdf); } catch (err) { console.error('An error occurred in main: ', err);