From 06649044ba9eb783c7f3b6b5599452061e884655 Mon Sep 17 00:00:00 2001 From: "Denise D." Date: Wed, 26 Aug 2026 17:33:56 +0200 Subject: [PATCH] changes in the flag unset (we consider both 0 and 1) --- src/hubspotConnector.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hubspotConnector.js b/src/hubspotConnector.js index 673db46..ccc84e9 100644 --- a/src/hubspotConnector.js +++ b/src/hubspotConnector.js @@ -153,15 +153,22 @@ async function runConnector() { try { console.log('Retrieving data from Keystone...', lastRunDate, tomorrowDate, isDryRun ); // getLeads(lastRunDate, currentDate, unsent, test) - const unsetValue = 0; + const firstUnsetValue = 1; + const secondUnsetValue = 0; const testValue = isDryRun ? 1 : 0; - const leads = await getLeads(lastRunDate, tomorrowDate, unsetValue, testValue); + const newLeads = await getLeads(lastRunDate, tomorrowDate, firstUnsetValue, testValue); + const oldLeads = await getLeads(lastRunDate, tomorrowDate, secondUnsetValue, testValue); - if (!leads.length) { + const allLeads = [...newLeads, ...oldLeads].filter( + (elem, index, self) => index === self.findIndex((el) => el.id === elem.id) + ); // questo evita duplicati basati sull'id + //console.log(allLeads); + + if (!allLeads.length) { console.log('No data retrieved.'); return; } - console.log('New leads:', leads.length); + console.log('New leads:', allLeads.length); // here we save the last time we ran the connector if (!isDryRun) { @@ -180,7 +187,7 @@ async function runConnector() { console.log('Connection successful!'); // leadsArray accepts either a single lead object or multiple leads(array) - const leadsArray = Array.isArray(leads) ? leads : [leads]; + const leadsArray = Array.isArray(allLeads) ? allLeads : [allLeads]; let allPayloads = (aggregateLeadsByEmail(leadsArray)).map(lead => mapFields(lead)); /*let nationalityOptions = '';