Scheduling infrastructure for absolutely everyone.
fix/request-reschedule-google-calendar-sync (#3157)
alannnc9a3624bb9a28
diff --git a/apps/web/pages/api/book/request-reschedule.ts b/apps/web/pages/api/book/request-reschedule.tsindex 6c7d7fc87a3..8a545281273 100644--- a/apps/web/pages/api/book/request-reschedule.ts+++ b/apps/web/pages/api/book/request-reschedule.ts@@ -193,38 +193,17 @@ const handler = async (if (bookingRef.type.endsWith("_calendar")) {const calendar = getCalendar(credentialsMap.get(bookingRef.type));- return calendar?.deleteEvent(bookingRef.uid, builder.calendarEvent);+ return calendar?.deleteEvent(+ bookingRef.uid,+ builder.calendarEvent,+ bookingRef.externalCalendarId+ );} else if (bookingRef.type.endsWith("_video")) {return deleteMeeting(credentialsMap.get(bookingRef.type), bookingRef.uid);}}});- // Updating attendee destinationCalendar if required- if (- bookingToReschedule.destinationCalendar &&- bookingToReschedule.destinationCalendar.userId &&- bookingToReschedule.destinationCalendar.integration.endsWith("_calendar")- ) {- const { destinationCalendar } = bookingToReschedule;- if (destinationCalendar.userId) {- const bookingRefsFiltered: BookingReference[] = bookingToReschedule.references.filter(- (ref) => !!credentialsMap.get(ref.type)- );- const attendeeData = await findUserDataByUserId(destinationCalendar.userId);- const attendeeCredentialsMap = new Map();- attendeeData.credentials.forEach((credential) => {- attendeeCredentialsMap.set(credential.type, credential);- });- bookingRefsFiltered.forEach((bookingRef) => {- if (bookingRef.uid) {- const calendar = getCalendar(attendeeCredentialsMap.get(destinationCalendar.integration));- calendar?.deleteEvent(bookingRef.uid, builder.calendarEvent);- }- });- }- }-// Send emailsawait sendRequestRescheduleEmail(builder.calendarEvent, {rescheduleLink: builder.rescheduleLink,diff --git a/packages/app-store/googlecalendar/lib/CalendarService.ts b/packages/app-store/googlecalendar/lib/CalendarService.tsindex 78fcd7ce43d..12409625767 100644--- a/packages/app-store/googlecalendar/lib/CalendarService.ts+++ b/packages/app-store/googlecalendar/lib/CalendarService.ts@@ -216,7 +216,7 @@ export default class GoogleCalendarService implements Calendar {});}- async deleteEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<void> {+ async deleteEvent(uid: string, event: CalendarEvent, externalCalendarId?: string | null): Promise<void> {return new Promise(async (resolve, reject) => {const auth = await this.auth;const myGoogleAuth = await auth.getToken();@@ -224,20 +224,27 @@ export default class GoogleCalendarService implements Calendar {version: "v3",auth: myGoogleAuth,});++ const defaultCalendarId = "primary";+ const calendarId = externalCalendarId ? externalCalendarId : event.destinationCalendar?.externalId;+calendar.events.delete({auth: myGoogleAuth,- calendarId: externalCalendarId ? externalCalendarId : event.destinationCalendar?.externalId,+ calendarId: calendarId ? calendarId : defaultCalendarId,eventId: uid,sendNotifications: true,sendUpdates: "all",},function (err: GoogleCalError | null, event) {if (err) {- /* 410 is when an event is already deleted on the Google cal before on cal.com- 404 is when the event is on a different calendar */+ /**+ * 410 is when an event is already deleted on the Google cal before on cal.com+ * 404 is when the event is on a different calendar+ */+ if (err.code === 410) return resolve();console.error("There was an error contacting google calendar service: ", err);- if (err.code === 410 || err.code === 404) return resolve();+ if (err.code === 404) return resolve();return reject(err);}return resolve(event?.data);