fix/request-reschedule-google-calendar-sync (#3157)

* Pass calendarId as parameter to deleteEvent()

* Updated deleteEvent param and default when sending calendarId
This commit is contained in:
alannnc authored and GitHub committed 2022-06-27 08:52:42 -06:00
1 parent 3449ad1a9f
commit 9a3624bb9a
2 files changed
+17 -31

No files matched your search

@@ -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);