Fixed Google Calendar custom destination calendar deletion (#1486)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Philip Niedertscheider 2022-01-13 20:47:15 +01:00 committed by GitHub
parent f8c036164c
commit 9c94aadbf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View file

@ -170,10 +170,10 @@ export const updateEvent = async (
};
};
export const deleteEvent = (credential: Credential, uid: string): Promise<unknown> => {
export const deleteEvent = (credential: Credential, uid: string, event: CalendarEvent): Promise<unknown> => {
const calendar = getCalendar(credential);
if (calendar) {
return calendar.deleteEvent(uid);
return calendar.deleteEvent(uid, event);
}
return Promise.resolve({});

View file

@ -66,7 +66,7 @@ export interface Calendar {
updateEvent(uid: string, event: CalendarEvent): Promise<any>;
deleteEvent(uid: string): Promise<unknown>;
deleteEvent(uid: string, event: CalendarEvent): Promise<unknown>;
getAvailability(
dateFrom: string,

View file

@ -185,7 +185,7 @@ export default class GoogleCalendarService implements Calendar {
);
}
async deleteEvent(uid: string): Promise<void> {
async deleteEvent(uid: string, event: CalendarEvent): Promise<void> {
return new Promise((resolve, reject) =>
this.auth.getToken().then((myGoogleAuth) => {
const calendar = google.calendar({
@ -195,7 +195,9 @@ export default class GoogleCalendarService implements Calendar {
calendar.events.delete(
{
auth: myGoogleAuth,
calendarId: "primary",
calendarId: event.destinationCalendar?.externalId
? event.destinationCalendar.externalId
: "primary",
eventId: uid,
sendNotifications: true,
sendUpdates: "all",

View file

@ -40,6 +40,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
email: true,
timeZone: true,
name: true,
destinationCalendar: true,
},
},
attendees: true,
@ -105,6 +106,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
uid: bookingToDelete?.uid,
location: bookingToDelete?.location,
language: t,
destinationCalendar: bookingToDelete?.user.destinationCalendar,
};
// Hook up the webhook logic here
@ -141,7 +143,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (credential.type.endsWith("_calendar")) {
const calendar = getCalendar(credential);
return calendar?.deleteEvent(bookingRefUid);
return calendar?.deleteEvent(bookingRefUid, evt);
} else if (credential.type.endsWith("_video")) {
return deleteMeeting(credential, bookingRefUid);
}