improvements in the config variable 'fields'

This commit is contained in:
Denise_Datinguinoo committed 2026-08-24 15:51:48 +02:00
1 parent a719252dd7
commit e3f87ad7b5
1 file changed
+14 -2
+14 -2
View File
@@ -29,6 +29,10 @@ async function initializeHubspotConnection() {
console.log('Hubspot connection is ready!'); 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 // 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 // remove fields sent to Hubspot, we only need to modify the varibale 'fields' without touching the mapping
// logic or the main function // logic or the main function
@@ -39,7 +43,12 @@ let fields = {
phone: (lead) => lead.contact?.phone ?? '', phone: (lead) => lead.contact?.phone ?? '',
nazionalita__c: (lead) => { nazionalita__c: (lead) => {
const country = lead.contact?.nationality_country?.country_name; 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('; ') ?? '', corso_keystone: (lead) => lead.programList?.join('; ') ?? '',
leadsource: () => 'keystone' leadsource: () => 'keystone'
@@ -64,6 +73,8 @@ function mapFields(lead) {
return obj; 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) { function aggregateLeadsByEmail(leads) {
const aggregatedLeads = new Map(); const aggregatedLeads = new Map();
@@ -99,6 +110,7 @@ async function createHubspotContacts(leadContacts) {
if (creationContacts) { if (creationContacts) {
console.log('Batches successfully created!'); console.log('Batches successfully created!');
console.log(JSON.stringify(creationContacts, null, 2)); console.log(JSON.stringify(creationContacts, null, 2));
return creationContacts;
} else { } else {
return 'Error in creating the contacts in Hubspot'; 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('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) { catch (error) {