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:
parent
3449ad1a9f
commit
9a3624bb9a
|
@ -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 emails
|
||||
await sendRequestRescheduleEmail(builder.calendarEvent, {
|
||||
rescheduleLink: builder.rescheduleLink,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user