Skip to content

Commit

Permalink
Only create event on the first destination calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
joeauyeung committed Apr 16, 2024
1 parent 58fb1fd commit 1a0707c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export default class EventManager {
};

if (event.destinationCalendar && event.destinationCalendar.length > 0) {
let eventCreated = false;
// Since GCal pushes events to multiple calendars we only want to create one event per booking
let gCalAdded = false;
const destinationCalendars: DestinationCalendar[] = event.destinationCalendar.reduce(
Expand All @@ -554,6 +555,7 @@ export default class EventManager {
[] as DestinationCalendar[]
);
for (const destination of destinationCalendars) {
if (eventCreated) break;
log.silly("Creating Calendar event", JSON.stringify({ destination }));
if (destination.credentialId) {
let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId);
Expand Down Expand Up @@ -582,6 +584,7 @@ export default class EventManager {
const createdEvent = await createEvent(credential, event, destination.externalId);
if (createdEvent) {
createdEvents.push(createdEvent);
eventCreated = true;
}
}
} else {
Expand All @@ -607,6 +610,7 @@ export default class EventManager {
})
);
createdEvents.push(await createEvent(firstCalendarCredential, event));
eventCreated = true;
}
}
}
Expand Down

0 comments on commit 1a0707c

Please sign in to comment.