Fix for bad primary calendar check (#7557)

pull/7542/head^2
Syed Ali Shahbaz 2023-03-07 21:17:10 +05:30 committed by GitHub
parent 0c94b0a30a
commit faaf935724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 12 deletions

View File

@ -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),