From 2e83c7fbf8282b2899ee3475bb850486ac90de6d Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Sat, 15 Oct 2022 14:02:24 -0300 Subject: [PATCH] Fixing bookings for all calendar-related apps (#5018) * Fixing bookings for apps * Missing assigning let var Co-authored-by: Peer Richelsen --- packages/core/EventManager.ts | 44 +++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index 344fbb70d5..0a3c75d1f1 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -303,6 +303,7 @@ export default class EventManager { private async createAllCalendarEvents(event: CalendarEvent) { /** Can I use destinationCalendar here? */ /* How can I link a DC to a cred? */ + let createdEvents: EventResult[] = []; if (event.destinationCalendar) { if (event.destinationCalendar.credentialId) { const credential = await prisma.credential.findFirst({ @@ -312,25 +313,38 @@ export default class EventManager { }); if (credential) { - return [await createEvent(credential, event)]; + createdEvents.push(await createEvent(credential, event)); } + } else { + const destinationCalendarCredentials = this.calendarCredentials.filter( + (c) => c.type === event.destinationCalendar?.integration + ); + createdEvents = createdEvents.concat( + await Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event))) + ); } - - const destinationCalendarCredentials = this.calendarCredentials.filter( - (c) => c.type === event.destinationCalendar?.integration - ); - return Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event))); + } else { + /** + * Not ideal but, if we don't find a destination calendar, + * fallback to the first connected calendar + */ + const [credential] = this.calendarCredentials; + if (!credential) { + return []; + } + createdEvents.push(await createEvent(credential, event)); } - /** - * Not ideal but, if we don't find a destination calendar, - * fallback to the first connected calendar - */ - const [credential] = this.calendarCredentials; - if (!credential) { - return []; - } - return [await createEvent(credential, event)]; + // Taking care of non-traditional calendar integrations + createdEvents = createdEvents.concat( + await Promise.all( + this.calendarCredentials + .filter((cred) => cred.type.includes("other_calendar")) + .map(async (cred) => await createEvent(cred, event)) + ) + ); + + return createdEvents; } /**