Fixing bookings for all calendar-related apps (#5018)

* Fixing bookings for apps

* Missing assigning let var

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
pull/5032/head
Leo Giovanetti 2022-10-15 14:02:24 -03:00 committed by GitHub
parent 1b215e4faf
commit 2e83c7fbf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 15 deletions

View File

@ -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<NewCalendarEventType>[] = [];
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;
}
/**