minor changes
This commit is contained in:
1 parent
d91e015f88
commit
e90e23a4d2
1 file changed
+14
-15
+14
-15
@@ -99,8 +99,15 @@ function aggregateLeadsByEmail(leads) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is the function where we create the Contacts in Hubspot
|
// this is the function where we create the Contacts in Hubspot
|
||||||
async function createHubspotContacts(leadContactsPayload) {
|
async function createHubspotContacts(leadContactsPayload, isDryRun) {
|
||||||
try {
|
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) {
|
for (let i = 0; i < leadContactsPayload.length; i += 100) {
|
||||||
let payloadsBatch = leadContactsPayload.slice(i, i + 100);
|
let payloadsBatch = leadContactsPayload.slice(i, i + 100);
|
||||||
const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch);
|
const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch);
|
||||||
@@ -122,9 +129,10 @@ async function createHubspotContacts(leadContactsPayload) {
|
|||||||
|
|
||||||
// this is the function that runs the connector
|
// this is the function that runs the connector
|
||||||
async function runConnector() {
|
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');
|
const isTestMode = process.argv.includes('--isTest') || process.argv.includes('--istest');
|
||||||
|
|
||||||
|
isDryRun = true;
|
||||||
// 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(); // we consider only the date of the current datestamp
|
let currentDate = new Date().toISOString(); // we consider only the date of the current datestamp
|
||||||
@@ -143,7 +151,9 @@ async function runConnector() {
|
|||||||
try {
|
try {
|
||||||
console.log('Retrieving data from Keystone...');
|
console.log('Retrieving data from Keystone...');
|
||||||
// getLeads(lastRunDate, currentDate, unsent, test)
|
// 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) {
|
if (!leads.length) {
|
||||||
console.log('No data retrieved.');
|
console.log('No data retrieved.');
|
||||||
@@ -169,16 +179,6 @@ async function runConnector() {
|
|||||||
// leadsArray accepts either a single lead object or multiple leads(array)
|
// leadsArray accepts either a single lead object or multiple leads(array)
|
||||||
const leadsArray = Array.isArray(leads) ? leads : [leads];
|
const leadsArray = Array.isArray(leads) ? leads : [leads];
|
||||||
let allPayloads = (aggregateLeadsByEmail(leadsArray)).map(lead => mapFields(lead));
|
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 = '';
|
/*let nationalityOptions = '';
|
||||||
try {
|
try {
|
||||||
@@ -194,9 +194,8 @@ async function runConnector() {
|
|||||||
throw new Error('Error in getting contacts properties');
|
throw new Error('Error in getting contacts properties');
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
allPayloads = [allPayloads[0]];
|
|
||||||
// Hubspot contacts creation
|
// Hubspot contacts creation
|
||||||
const hubspotContacts = await createHubspotContacts(allPayloads);
|
const hubspotContacts = await createHubspotContacts(allPayloads, isDryRun);
|
||||||
console.log('HubSpot Batch Response:', hubspotContacts);
|
console.log('HubSpot Batch Response:', hubspotContacts);
|
||||||
|
|
||||||
console.log('All contacts have been created!');
|
console.log('All contacts have been created!');
|
||||||
|
|||||||
Reference in new issue
Block a user