improvements about dryRun mode

This commit is contained in:
Denise_Datinguinoo committed 2026-08-25 16:42:30 +02:00
1 parent 83ccf3ed04
commit 835b7eb918
2 files changed
+21 -22

No files matched your search

+20 -21
View File
@@ -103,8 +103,7 @@ async function createHubspotContacts(leadContactsPayload) {
try { try {
for (let i = 0; i < leadContactsPayload.length; i += 100) { for (let i = 0; i < leadContactsPayload.length; i += 100) {
let payloadsBatch = leadContactsPayload.slice(i, i + 100); let payloadsBatch = leadContactsPayload.slice(i, i + 100);
let payloadTest = [leadContactsPayload[0]]; const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch);
const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadTest);
if (creationContacts) { if (creationContacts) {
console.log('Batch successfully created!'); console.log('Batch successfully created!');
console.log(JSON.stringify(creationContacts, null, 2)); console.log(JSON.stringify(creationContacts, null, 2));
@@ -128,7 +127,7 @@ async function runConnector() {
// here we consider the last time we ran the connector // here we consider the last time we ran the connector
let lastRunDate = ''; // we will use this to simplify the management of the leads let lastRunDate = ''; // we will use this to simplify the management of the leads
let currentDate = new Date().toISOString().split('T')[0]; // we consider only the date of the current datestamp let currentDate = new Date().toISOString(); // we consider only the date of the current datestamp
if (fs.existsSync(FILE_PATH)) { if (fs.existsSync(FILE_PATH)) {
const file = fs.readFileSync(FILE_PATH, 'utf8'); const file = fs.readFileSync(FILE_PATH, 'utf8');
lastRunDate = JSON.parse(file).lastRun; lastRunDate = JSON.parse(file).lastRun;
@@ -150,6 +149,16 @@ async function runConnector() {
console.log('No data retrieved.'); console.log('No data retrieved.');
return; return;
} }
// here we save the last time we ran the connector
if (!isTestMode) {
// default : 2026-08-18;
fs.writeFileSync(FILE_PATH, JSON.stringify({ lastRun: currentDate }, null, 2));
console.log('DateTime saved successfully in file last-modified-date.json');
} else {
console.log('TEST/DRY MODE: Date not modified on JSON file.');
}
console.log('Data retrieved successfully!'); console.log('Data retrieved successfully!');
console.log('Now Connecting to Hubspot...'); console.log('Now Connecting to Hubspot...');
@@ -157,17 +166,20 @@ async function runConnector() {
await initializeHubspotConnection(); await initializeHubspotConnection();
console.log('Connection successful!'); console.log('Connection successful!');
// 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) { if (isDryRun) {
console.log('--- DRY RUN MODE: No changes will be saved to HubSpot ---'); console.log('--- DRY RUN MODE: No changes will be saved to HubSpot ---');
console.log('Preview Lead 1:'); console.log('Preview Lead 1:');
const leadsTest = aggregateLeadsByEmail(leads); const leadTest = [allPayloads[0]];
console.log(`ID: ${ leadsTest[0].id }`); console.log(leadTest);
console.log(mapFields(leadsTest[0]));
console.log('Process DRY-RUN completed!'); console.log('Process DRY-RUN completed!');
return; return;
} }
else {
/*let nationalityOptions = ''; /*let nationalityOptions = '';
try { try {
const contactsProperties = await hubspot.getObjectProperties('contacts'); const contactsProperties = await hubspot.getObjectProperties('contacts');
@@ -182,26 +194,13 @@ async function runConnector() {
throw new Error('Error in getting contacts properties'); throw new Error('Error in getting contacts properties');
}*/ }*/
// leadsArray accepts either a single lead object or multiple leads(array) allPayloads = [allPayloads[0]];
const leadsArray = Array.isArray(leads) ? leads : [leads];
const allPayloads = (aggregateLeadsByEmail(leadsArray)).map(lead => mapFields(lead));
// Hubspot contacts creation // Hubspot contacts creation
const hubspotContacts = await createHubspotContacts(allPayloads); const hubspotContacts = await createHubspotContacts(allPayloads);
console.log('HubSpot Batch Response:', hubspotContacts); console.log('HubSpot Batch Response:', hubspotContacts);
// here we save the last time we ran the connector
if (!isTestMode) {
// default : 2026-08-18;
fs.writeFileSync(FILE_PATH, JSON.stringify({ lastRun: currentDate }, null, 2));
console.log('DateTime saved successfully in file last-modified-date.json');
} else {
console.log('TEST/DRY MODE: Date not modified on JSON file.');
}
console.log('All contacts have been created!'); console.log('All contacts have been created!');
} }
}
catch (error) { catch (error) {
console.error('Error in processing data: ', error.message); console.error('Error in processing data: ', error.message);
} }
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"lastRun": "2026-08-18" "lastRun": "2026-08-25T14:25:46.866Z"
} }