From e90e23a4d2d0f8ab699b1a23109bb2ea1c312e86 Mon Sep 17 00:00:00 2001 From: "Denise D." Date: Tue, 25 Aug 2026 17:24:36 +0200 Subject: [PATCH] minor changes --- src/hubspotConnector.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/hubspotConnector.js b/src/hubspotConnector.js index 58512a3..dcfe908 100644 --- a/src/hubspotConnector.js +++ b/src/hubspotConnector.js @@ -99,8 +99,15 @@ function aggregateLeadsByEmail(leads) { } // this is the function where we create the Contacts in Hubspot -async function createHubspotContacts(leadContactsPayload) { +async function createHubspotContacts(leadContactsPayload, isDryRun) { try { + if (isDryRun) { + console.log('--- DRY RUN MODE: No changes will be saved to HubSpot ---'); + console.log('Preview Lead 1:'); + console.log([leadContactsPayload[0]]); + console.log('Process DRY-RUN completed!'); + return 'DRY-RUN mode successful'; + } for (let i = 0; i < leadContactsPayload.length; i += 100) { let payloadsBatch = leadContactsPayload.slice(i, i + 100); const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch); @@ -122,9 +129,10 @@ async function createHubspotContacts(leadContactsPayload) { // this is the function that runs the connector async function runConnector() { - const isDryRun = process.argv.includes('--dryRun') || process.argv.includes('--dryrun'); + let isDryRun = process.argv.includes('--dryRun') || process.argv.includes('--dryrun'); const isTestMode = process.argv.includes('--isTest') || process.argv.includes('--istest'); + isDryRun = true; // here we consider the last time we ran the connector let lastRunDate = ''; // we will use this to simplify the management of the leads let currentDate = new Date().toISOString(); // we consider only the date of the current datestamp @@ -143,7 +151,9 @@ async function runConnector() { try { console.log('Retrieving data from Keystone...'); // getLeads(lastRunDate, currentDate, unsent, test) - const leads = await getLeads(lastRunDate, currentDate, 1, 1); + const unsetValue = 1; + const testValue = isDryRun ? 1 : 0; + const leads = await getLeads(lastRunDate, currentDate, unsetValue, testValue); if (!leads.length) { console.log('No data retrieved.'); @@ -169,16 +179,6 @@ async function runConnector() { // leadsArray accepts either a single lead object or multiple leads(array) const leadsArray = Array.isArray(leads) ? leads : [leads]; let allPayloads = (aggregateLeadsByEmail(leadsArray)).map(lead => mapFields(lead)); - - if (isDryRun) { - console.log('--- DRY RUN MODE: No changes will be saved to HubSpot ---'); - console.log('Preview Lead 1:'); - const leadTest = [allPayloads[0]]; - console.log(leadTest); - - console.log('Process DRY-RUN completed!'); - return; - } /*let nationalityOptions = ''; try { @@ -194,9 +194,8 @@ async function runConnector() { throw new Error('Error in getting contacts properties'); }*/ - allPayloads = [allPayloads[0]]; // Hubspot contacts creation - const hubspotContacts = await createHubspotContacts(allPayloads); + const hubspotContacts = await createHubspotContacts(allPayloads, isDryRun); console.log('HubSpot Batch Response:', hubspotContacts); console.log('All contacts have been created!');