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) { private async createAllCalendarEvents(event: CalendarEvent) {
/** Can I use destinationCalendar here? */ /** Can I use destinationCalendar here? */
/* How can I link a DC to a cred? */ /* How can I link a DC to a cred? */
let createdEvents: EventResult<NewCalendarEventType>[] = [];
if (event.destinationCalendar) { if (event.destinationCalendar) {
if (event.destinationCalendar.credentialId) { if (event.destinationCalendar.credentialId) {
const credential = await prisma.credential.findFirst({ const credential = await prisma.credential.findFirst({
@ -312,25 +313,38 @@ export default class EventManager {
}); });
if (credential) { 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)))
);
} }
} else {
const destinationCalendarCredentials = this.calendarCredentials.filter( /**
(c) => c.type === event.destinationCalendar?.integration * Not ideal but, if we don't find a destination calendar,
); * fallback to the first connected calendar
return Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event))); */
const [credential] = this.calendarCredentials;
if (!credential) {
return [];
}
createdEvents.push(await createEvent(credential, event));
} }
/** // Taking care of non-traditional calendar integrations
* Not ideal but, if we don't find a destination calendar, createdEvents = createdEvents.concat(
* fallback to the first connected calendar await Promise.all(
*/ this.calendarCredentials
const [credential] = this.calendarCredentials; .filter((cred) => cred.type.includes("other_calendar"))
if (!credential) { .map(async (cred) => await createEvent(cred, event))
return []; )
} );
return [await createEvent(credential, event)];
return createdEvents;
} }
/** /**