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:
parent
f8c036164c
commit
9c94aadbf7
4 changed files with 10 additions and 6 deletions
|
@ -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({});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue