fix: handle collective multiple host on destinationCalendar#8
Conversation
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| const selectedCalendar = externalCalendarId | ||
| ? externalCalendarId | ||
| : event.destinationCalendar?.externalId; | ||
| : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; |
There was a problem hiding this comment.
Bug: Calendar Selection Fails Without Explicit ID
When externalCalendarId is not provided (null/undefined), the fallback logic attempts to find a calendar where cal.externalId === externalCalendarId, which will never match since it's comparing against a falsy value. This breaks calendar selection when no explicit calendar ID is provided, likely causing events to fail updating on the correct calendar.
| const calendarId = externalCalendarId ? externalCalendarId : event.destinationCalendar?.externalId; | ||
| const calendarId = externalCalendarId | ||
| ? externalCalendarId | ||
| : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; |
There was a problem hiding this comment.
Bug: Fallback Logic Fails Calendar Selection
When externalCalendarId is not provided (null/undefined), the fallback logic attempts to find a calendar where cal.externalId === externalCalendarId, which will never match since it's comparing against a falsy value. This breaks calendar selection when no explicit calendar ID is provided, preventing events from being deleted from the correct calendar.
| ...(IS_TEAM_BILLING_ENABLED ? { slug } : {}), | ||
| metadata: { | ||
| ...(IS_TEAM_BILLING_ENABLED && { requestedSlug: slug }), | ||
| ...(IS_TEAM_BILLING_ENABLED ? { requestedSlug: slug } : {}), |
There was a problem hiding this comment.
Bug: Billing Logic Inverts Organization Slugs
The conditional logic for slug assignment is inverted. When IS_TEAM_BILLING_ENABLED is true, it sets slug directly (should only happen when billing is disabled), and when false, it doesn't set slug (but should). This causes organizations to have incorrect slug configuration based on billing status, breaking organization URL routing.
| if (evt.location === MeetLocationType && evt.destinationCalendar?.integration !== "google_calendar") { | ||
| // @NOTE: destinationCalendar it's an array now so as a fallback we will only check the first one | ||
| const [mainHostDestinationCalendar] = evt.destinationCalendar ?? []; | ||
| if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") { |
There was a problem hiding this comment.
Bug: Missing Calendar Breaks Event Creation
When evt.destinationCalendar is null, undefined, or empty, mainHostDestinationCalendar becomes undefined. Accessing mainHostDestinationCalendar.integration without optional chaining throws a runtime error when checking if Google Meet fallback is needed. This breaks event creation for bookings without a destination calendar.
Test 4
Replicated from ai-code-review-evaluation/cal.com-cursor#4
Note
Migrate
destinationCalendarfrom single object to array and update core flows and calendar integrations to create/update/delete events per-credential/calendar, with accompanying type and test updates.destinationCalendarnow an array across booking creation, cancellation, reminders, confirmations, reschedule, and edits; fallback wraps single values into arrays.externalIdandcredentialId.createEvent(event, credentialId)selects matching calendar bycredentialId; organizer attendee email uses selected destination; default toprimaryif none.[0]) for externalId; list/cal filters consider primary from first.CalendarManager.createEventpassescredential.id;EventManagercreates events per destination, fetching missing credentials from DB; updates handle multiple calendar references.CalendarEvent.destinationCalendar: DestinationCalendar[] | null.Calendar.createEvent(event, credentialId); addschedulingTypetoCalendarEvent;EventResultgainsexternalId.destinationCalendar: []).Written by Cursor Bugbot for commit bd797c1. Configure here.