Adding debugging info (#3706)
parent
da638c4b1b
commit
7747b3d9a0
|
@ -188,8 +188,10 @@ export default class HubspotOtherCalendarService implements Calendar {
|
|||
async handleMeetingCreation(event: CalendarEvent, contacts: SimplePublicObjectInput[]) {
|
||||
const meetingEvent = await this.hubspotCreateMeeting(event);
|
||||
if (meetingEvent) {
|
||||
this.log.debug("meeting:creation:ok", { meetingEvent });
|
||||
const associatedMeeting = await this.hubspotAssociate(meetingEvent, contacts);
|
||||
if (associatedMeeting) {
|
||||
this.log.debug("association:creation:ok", { associatedMeeting });
|
||||
return Promise.resolve({
|
||||
uid: meetingEvent.id,
|
||||
id: meetingEvent.id,
|
||||
|
@ -201,6 +203,7 @@ export default class HubspotOtherCalendarService implements Calendar {
|
|||
}
|
||||
return Promise.reject("Something went wrong when associating the meeting and attendees in HubSpot");
|
||||
}
|
||||
this.log.debug("meeting:creation:notOk", { meetingEvent, event, contacts });
|
||||
return Promise.reject("Something went wrong when creating a meeting in HubSpot");
|
||||
}
|
||||
|
||||
|
@ -211,26 +214,35 @@ export default class HubspotOtherCalendarService implements Calendar {
|
|||
if (contacts.length) {
|
||||
if (contacts.length == event.attendees.length) {
|
||||
// All attendees do exist in HubSpot
|
||||
this.log.debug("contact:search:all", { event, contacts });
|
||||
return await this.handleMeetingCreation(event, contacts);
|
||||
} else {
|
||||
// Some attendees don't exist in HubSpot
|
||||
// Get the existing contacts' email to filter out
|
||||
this.log.debug("contact:search:notAll", { event, contacts });
|
||||
const existingContacts = contacts.map((contact) => contact.properties.email);
|
||||
this.log.debug("contact:filter:existing", { existingContacts });
|
||||
// Get non existing contacts filtering out existing from attendees
|
||||
const nonExistingContacts = event.attendees.filter(
|
||||
(attendee) => !existingContacts.includes(attendee.email)
|
||||
);
|
||||
this.log.debug("contact:filter:nonExisting", { nonExistingContacts });
|
||||
// Only create contacts in HubSpot that were not present in the previous contact search
|
||||
const createContacts = await this.hubspotContactCreate(nonExistingContacts);
|
||||
this.log.debug("contact:created", { createContacts });
|
||||
// Continue with meeting creation and association only when all contacts are present in HubSpot
|
||||
if (createContacts.length) {
|
||||
this.log.debug("contact:creation:ok");
|
||||
return await this.handleMeetingCreation(event, createContacts.concat(contacts));
|
||||
}
|
||||
return Promise.reject("Something went wrong when creating non-existing attendees in HubSpot");
|
||||
}
|
||||
} else {
|
||||
this.log.debug("contact:search:none", { event, contacts });
|
||||
const createContacts = await this.hubspotContactCreate(event.attendees);
|
||||
this.log.debug("contact:created", { createContacts });
|
||||
if (createContacts.length) {
|
||||
this.log.debug("contact:creation:ok");
|
||||
return await this.handleMeetingCreation(event, createContacts);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue