1 parent
b287f7e047
commit
2ce1828841
1 file changed
+16
-1
@@ -482,6 +482,7 @@ export default class SalesforceCRMService implements CRM {
|
||||
organizerEmail?: string,
|
||||
calEventResponses?: CalEventResponses | null
|
||||
) {
|
||||
const log = logger.getSubLogger({ prefix: [`[getContacts]`] });
|
||||
const conn = await this.conn;
|
||||
const appOptions = this.getAppOptions();
|
||||
const createEventOn = appOptions.createEventOn ?? SalesforceRecordEnum.CONTACT;
|
||||
@@ -489,6 +490,8 @@ export default class SalesforceCRMService implements CRM {
|
||||
const organizerId = organizerEmail ? await this.getSalesforceUserIdFromEmail(organizerEmail) : undefined;
|
||||
const createdContacts: { id: string; email: string }[] = [];
|
||||
|
||||
log.info("createContacts", safeStringify({ createEventOn, organizerId, contactsToCreate }));
|
||||
|
||||
if (createEventOn === SalesforceRecordEnum.CONTACT) {
|
||||
await Promise.all(
|
||||
contactsToCreate.map(async (attendee) => {
|
||||
@@ -524,6 +527,11 @@ export default class SalesforceCRMService implements CRM {
|
||||
if (createdAccountContacts.length > 0) {
|
||||
createdContacts.push(...createdAccountContacts);
|
||||
}
|
||||
} else {
|
||||
log.info(
|
||||
"createEventOn=LEAD, No account found for attendee, not creating a contact",
|
||||
safeStringify({ attendeeEmail: attendee.email })
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await this.createAttendeeRecord({
|
||||
@@ -696,6 +704,7 @@ export default class SalesforceCRMService implements CRM {
|
||||
}
|
||||
|
||||
private getDominantAccountId(contacts: { AccountId: string }[]) {
|
||||
const log = logger.getSubLogger({ prefix: [`[getDominantAccountId]:${contacts}`] });
|
||||
// To get the dominant AccountId we only need to iterate through half the array
|
||||
const iterateLength = Math.ceil(contacts.length / 2);
|
||||
// Store AccountId frequencies
|
||||
@@ -719,6 +728,7 @@ export default class SalesforceCRMService implements CRM {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Dominant AccountId", safeStringify({ dominantAccountId }));
|
||||
return dominantAccountId;
|
||||
}
|
||||
|
||||
@@ -735,6 +745,8 @@ export default class SalesforceCRMService implements CRM {
|
||||
accountId?: string;
|
||||
calEventResponses?: CalEventResponses | null;
|
||||
}) {
|
||||
const log = logger.getSubLogger({ prefix: [`[createAttendeeRecord]:${attendee.email}`] });
|
||||
log.info("createAttendeeRecord", safeStringify({ attendee, recordType, organizerId, accountId }));
|
||||
const conn = await this.conn;
|
||||
|
||||
const createBody = await this.generateCreateRecordBody({
|
||||
@@ -866,7 +878,8 @@ export default class SalesforceCRMService implements CRM {
|
||||
private async getAccountIdBasedOnEmailDomainOfContacts(email: string) {
|
||||
const conn = await this.conn;
|
||||
const emailDomain = email.split("@")[1];
|
||||
|
||||
const log = logger.getSubLogger({ prefix: [`[getAccountIdBasedOnEmailDomainOfContacts]:${email}`] });
|
||||
log.info("getAccountIdBasedOnEmailDomainOfContacts", safeStringify({ email, emailDomain }));
|
||||
// First check if an account has the same website as the email domain of the attendee
|
||||
const accountQuery = await conn.query(
|
||||
`SELECT Id, Website FROM Account WHERE Website LIKE '%${emailDomain}%' LIMIT 1`
|
||||
@@ -1224,6 +1237,8 @@ export default class SalesforceCRMService implements CRM {
|
||||
accountId: string;
|
||||
organizerId?: string;
|
||||
}) {
|
||||
const log = logger.getSubLogger({ prefix: [`[createNewContactUnderAnAccount]:${attendee.email}`] });
|
||||
log.info("createNewContactUnderAnAccount", safeStringify({ attendee, accountId, organizerId }));
|
||||
const conn = await this.conn;
|
||||
|
||||
// First see if the contact already exists and connect it to the account
|
||||
|
||||
Reference in new issue
Block a user