From faaf935724d35bb667ffd417b12104bc5eba4e5e Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Tue, 7 Mar 2023 21:17:10 +0530 Subject: [PATCH] Fix for bad primary calendar check (#7557) --- packages/core/CalendarManager.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index ea01c57f0f..f5f4ba3673 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -44,7 +44,6 @@ export const getConnectedCalendars = async ( calendarCredentials.map(async (item) => { try { const { calendar, integration, credential } = item; - let primary!: IntegrationCalendar; // Don't leak credentials to the client const credentialId = credential.id; @@ -57,12 +56,7 @@ export const getConnectedCalendars = async ( const cals = await calendar.listCalendars(); const calendars = _(cals) .map((cal) => { - if (cal.primary) { - primary = { ...cal, credentialId }; - } - if (cal.externalId === destinationCalendarExternalId) { - destinationCalendar = cal; - } + if (cal.externalId === destinationCalendarExternalId) destinationCalendar = cal; return { ...cal, readOnly: cal.readOnly || false, @@ -73,11 +67,7 @@ export const getConnectedCalendars = async ( }) .sortBy(["primary"]) .value(); - - if (primary && destinationCalendar) { - destinationCalendar.primaryEmail = primary.email; - destinationCalendar.integrationTitle = integration.title; - } + const primary = calendars.find((item) => item.primary) ?? calendars.find((cal) => cal !== undefined); if (!primary) { return { integration, @@ -87,6 +77,10 @@ export const getConnectedCalendars = async ( }, }; } + if (destinationCalendar) { + destinationCalendar.primaryEmail = primary.email; + destinationCalendar.integrationTitle = integration.title; + } return { integration: cleanIntegrationKeys(integration),