From f2a59fe4e8405ab3ee4669dc2e54a13c41cf5a07 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Tue, 5 Dec 2023 21:46:54 +0530 Subject: [PATCH] Fix booking error in case of no calendar credential but stray destinationCalendar (#12680) --- packages/core/EventManager.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index 4aa5e30beb..edfd96d3a3 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -574,24 +574,25 @@ export default class EventManager { (c) => c.type === destination.integration ); // It might not be the first connected calendar as it seems that the order is not guaranteed to be ascending of credentialId. - const firstCalendarCredential = destinationCalendarCredentials[0]; + const firstCalendarCredential = destinationCalendarCredentials[0] as + | (typeof destinationCalendarCredentials)[number] + | undefined; if (!firstCalendarCredential) { log.warn( "No other credentials found of the same type as the destination calendar. Falling back to first connected calendar" ); await fallbackToFirstConnectedCalendar(); + } else { + log.warn( + "No credentialId found for destination calendar, falling back to first found calendar of same type as destination calendar", + safeStringify({ + destination: getPiiFreeDestinationCalendar(destination), + firstConnectedCalendar: getPiiFreeCredential(firstCalendarCredential), + }) + ); + createdEvents.push(await createEvent(firstCalendarCredential, event)); } - - log.warn( - "No credentialId found for destination calendar, falling back to first found calendar", - safeStringify({ - destination: getPiiFreeDestinationCalendar(destination), - firstConnectedCalendar: getPiiFreeCredential(firstCalendarCredential), - }) - ); - - createdEvents.push(await createEvent(firstCalendarCredential, event)); } } } else {