What does this PR do?
When a host reschedules a booking, this now checks if the guest (attendee) is a Cal.com user. If they are, the system fetches their availability and only shows time slots when both the host and the guest are available.
This prevents hosts from rescheduling to times when the guest is busy, improving the rescheduling experience for both parties.
Closes #16378
/claim #16378
Changes
- Added
filterSlotsByGuestAvailability() private method to AvailableSlotsService in packages/trpc/server/routers/viewer/slots/util.ts
- Integrates into
_getAvailableSlots() when rescheduleUid is present
- Uses existing APIs only:
BookingRepository, UserRepository, UserAvailabilityService
How it works
- When
rescheduleUid is present, fetch the original booking and its attendees
- For each attendee, check if they’re a Cal.com user via
UserRepository.findByEmail()
- If yes, fetch their availability via
UserAvailabilityService.getUsersAvailability()
- Collect all guest busy times and filter out conflicting slots using
checkForConflicts()
Edge cases handled
- Guest is not a Cal.com user → host-only availability (no change)
- Multiple guests → all guests’ busy times are combined
- Guest has no busy times → all slots remain available
- Error fetching guest availability → graceful fallback to host-only availability
- Host email in attendees list → skipped (already accounted for)
Tests added (8 test cases)
- Returns all slots when booking not found
- Returns all slots when booking has no attendees
- Returns all slots when guest is not a Cal.com user
- Filters slots when guest is a Cal.com user with busy times
- Handles multiple Cal.com guests (intersects busy times)
- Skips host email in attendees list
- Graceful fallback on error
- Returns all slots when guest has no busy times