diff --git a/src/hubspotConnector.js b/src/hubspotConnector.js index a04f59f..6be798f 100644 --- a/src/hubspotConnector.js +++ b/src/hubspotConnector.js @@ -29,6 +29,10 @@ async function initializeHubspotConnection() { console.log('Hubspot connection is ready!'); } +const countryMapping = { + 'Vietnam': 'VIET NAM', + 'Congo, DR': 'CONGO' +}; // this config variable is used to map Hubspot fields to those from Keystone, so that when we have to add or // remove fields sent to Hubspot, we only need to modify the varibale 'fields' without touching the mapping // logic or the main function @@ -39,7 +43,12 @@ let fields = { phone: (lead) => lead.contact?.phone ?? '', nazionalita__c: (lead) => { const country = lead.contact?.nationality_country?.country_name; - return typeof country === 'string' ? country.toUpperCase() : ''; + if (!country || typeof country !== 'string') { + return undefined; + } + + const targetCountry = countryMapping[country] || country; + return targetCountry.toUpperCase(); }, corso_keystone: (lead) => lead.programList?.join('; ') ?? '', leadsource: () => 'keystone' @@ -64,6 +73,8 @@ function mapFields(lead) { return obj; } +// in Keystone there are duplicate leads but with different program name, so in here we aggregate the same leads +// and we put the programs' name into a single field named 'programList' function aggregateLeadsByEmail(leads) { const aggregatedLeads = new Map(); @@ -99,6 +110,7 @@ async function createHubspotContacts(leadContacts) { if (creationContacts) { console.log('Batches successfully created!'); console.log(JSON.stringify(creationContacts, null, 2)); + return creationContacts; } else { return 'Error in creating the contacts in Hubspot'; } @@ -177,7 +189,7 @@ async function runConnector() { console.log('DateTime saved successfully in file last-modified-date.json'); }*/ - //console.log('All contacts have been created!'); + console.log('All contacts have been created!'); } } catch (error) {