@@ -34,7 +34,7 @@ type ContactCreateResult = {
3434 } ;
3535} ;
3636
37- export default class HubspotRevertCalendarService implements Calendar {
37+ export default class HubSpotRevertCalendarService implements Calendar {
3838 private log : typeof logger ;
3939 private tenantId : string ;
4040 private revertApiKey : string ;
@@ -78,26 +78,22 @@ export default class HubspotRevertCalendarService implements Calendar {
7878 } ;
7979
8080 private contactSearch = async ( event : CalendarEvent ) => {
81- const attendeeEmails = event . attendees . map ( ( attendee ) => attendee . email ) ;
82-
8381 const headers = new Headers ( ) ;
8482 headers . append ( "x-revert-api-token" , this . revertApiKey ) ;
8583 headers . append ( "x-revert-t-id" , this . tenantId ) ;
8684 headers . append ( "Content-Type" , "application/json" ) ;
8785
8886 const bodyRaw = JSON . stringify ( {
8987 searchCriteria : {
90- filterGroups : [
91- {
92- filters : [
93- {
94- propertyName : "email" ,
95- operator : "IN" ,
96- values : attendeeEmails ,
97- } ,
98- ] ,
99- } ,
100- ] ,
88+ filterGroups : event . attendees . map ( ( attendee ) => ( {
89+ filters : [
90+ {
91+ value : attendee . email ,
92+ propertyName : "email" ,
93+ operator : "EQ" ,
94+ } ,
95+ ] ,
96+ } ) ) ,
10197 } ,
10298 } ) ;
10399
@@ -124,7 +120,7 @@ export default class HubspotRevertCalendarService implements Calendar {
124120 } `;
125121 } ;
126122
127- private createHubspotEvent = async ( event : CalendarEvent , contacts : CalendarEvent [ "attendees" ] ) => {
123+ private createHubSpotEvent = async ( event : CalendarEvent , contacts : CalendarEvent [ "attendees" ] ) => {
128124 const eventPayload = {
129125 subject : event . title ,
130126 startDateTime : event . startTime ,
@@ -187,7 +183,7 @@ export default class HubspotRevertCalendarService implements Calendar {
187183 } ;
188184
189185 async handleEventCreation ( event : CalendarEvent , contacts : CalendarEvent [ "attendees" ] ) {
190- const meetingEvent = await ( await this . createHubspotEvent ( event , contacts ) ) . json ( ) ;
186+ const meetingEvent = await ( await this . createHubSpotEvent ( event , contacts ) ) . json ( ) ;
191187 if ( meetingEvent && meetingEvent . status === "ok" ) {
192188 this . log . debug ( "event:creation:ok" , { meetingEvent } ) ;
193189 return Promise . resolve ( {
@@ -200,7 +196,7 @@ export default class HubspotRevertCalendarService implements Calendar {
200196 } ) ;
201197 }
202198 this . log . debug ( "meeting:creation:notOk" , { meetingEvent, event, contacts } ) ;
203- return Promise . reject ( "Something went wrong when creating a meeting in PipedriveCRM " ) ;
199+ return Promise . reject ( "Something went wrong when creating a meeting in HubSpot CRM " ) ;
204200 }
205201
206202 async createEvent ( event : CalendarEvent ) : Promise < NewCalendarEventType > {
@@ -221,7 +217,7 @@ export default class HubspotRevertCalendarService implements Calendar {
221217 } ) ;
222218 return await this . handleEventCreation ( event , existingPeople ) ;
223219 } else {
224- // Some attendees don't exist in PipedriveCRM
220+ // Some attendees don't exist in HubSpot CRM
225221 // Get the existing contacts' email to filter out
226222 this . log . debug ( "contact:search:notAll" , { event, contacts } ) ;
227223 const existingContacts = contacts . results . map ( ( contact ) => contact . email ) ;
@@ -231,7 +227,7 @@ export default class HubspotRevertCalendarService implements Calendar {
231227 ( attendee ) => ! existingContacts . includes ( attendee . email )
232228 ) ;
233229 this . log . debug ( "contact:filter:nonExisting" , { nonExistingContacts } ) ;
234- // Only create contacts in PipedriveCRM that were not present in the previous contact search
230+ // Only create contacts in HubSpot CRM that were not present in the previous contact search
235231 const createdContacts = await this . createContacts ( nonExistingContacts ) ;
236232 this . log . debug ( "contact:created" , { createdContacts } ) ;
237233 // Continue with event creation and association only when all contacts are present in hubspot
@@ -265,7 +261,7 @@ export default class HubspotRevertCalendarService implements Calendar {
265261 return await this . handleEventCreation ( event , allContacts ) ;
266262 }
267263 return Promise . reject ( {
268- calError : "Something went wrong when creating non-existing attendees in PipedriveCRM " ,
264+ calError : "Something went wrong when creating non-existing attendees in HubSpot CRM " ,
269265 } ) ;
270266 }
271267 } else {
@@ -287,7 +283,7 @@ export default class HubspotRevertCalendarService implements Calendar {
287283 }
288284 }
289285 return Promise . reject ( {
290- calError : "Something went wrong when searching/creating the attendees in PipedriveCRM " ,
286+ calError : "Something went wrong when searching/creating the attendees in HubSpot CRM " ,
291287 } ) ;
292288 }
293289
@@ -315,7 +311,7 @@ export default class HubspotRevertCalendarService implements Calendar {
315311 } ) ;
316312 }
317313 this . log . debug ( "meeting:updation:notOk" , { meetingEvent, event } ) ;
318- return Promise . reject ( "Something went wrong when updating a meeting in PipedriveCRM " ) ;
314+ return Promise . reject ( "Something went wrong when updating a meeting in HubSpot CRM " ) ;
319315 }
320316
321317 async deleteEvent ( uid : string ) : Promise < void > {
0 commit comments