Skip to content

feat(repos): add guest-availability booking + user lookup methods#28908

Closed
bcornish1797 wants to merge 1 commit intocalcom:mainfrom
bcornish1797:feat/16378-part-a-repos
Closed

feat(repos): add guest-availability booking + user lookup methods#28908
bcornish1797 wants to merge 1 commit intocalcom:mainfrom
bcornish1797:feat/16378-part-a-repos

Conversation

@bcornish1797
Copy link
Copy Markdown

@bcornish1797 bcornish1797 commented Apr 15, 2026

First of three PRs splitting #28636 for easier review.

Adds two lookup methods on BookingRepository (findByUidIncludeAttendeeEmails, findByUserIdsAndDateRange) and one on UserRepository (findByEmails). No call sites yet; this is pure data-access infra that Parts B (#28909) and C (#28911) build on. Together the three implement the guest-availability-on-host-reschedule scope from #16378.

Unit tests use vi.fn() mocks, follow the existing BookingRepository.test.ts / UserRepository.test.ts patterns. No schema or dependency changes.

Split of calcom#28636 (Part A of 3). Pure additive infra — no call sites change
and no existing behaviour is altered. This layer is the data-access
foundation that Parts B (frontend `rescheduledBy` plumbing) and C
(slots/util.ts business logic) build on.

BookingRepository:
  - findByUidIncludeAttendeeEmails(uid): fetches an original booking's
    attendee emails and the host user's email, used to detect who the
    reschedule initiator is and resolve attendees to Cal.com users.
  - findByUserIdsAndDateRange({ userIds, userEmails, dateFrom, dateTo,
    excludeUid? }): finds ACCEPTED/PENDING bookings overlapping a date
    range by userId or attendee email (case-insensitive), with an
    excludeUid parameter applied at the database level so the caller
    cannot accidentally include the very booking being rescheduled.

UserRepository:
  - findByEmails({ emails }): resolves a list of emails to Cal.com
    users, checking both primary email and verified secondary emails,
    case-insensitively, with input deduplication before the query and
    output deduplication by user id. Uses Promise.all to fan out the two
    lookups concurrently.

Tests cover: empty-input short-circuits, primary vs secondary lookup,
dedup across both lookups, case-insensitive normalization, excludeUid,
OR clause composition, and the select shape used downstream.
@github-actions
Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @bcornish1797! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3011eebafb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2147 to +2149
attendees: { select: { email: true } },
user: { select: { email: true } },
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include host email fallback in booking lookup select

findByUidIncludeAttendeeEmails only selects user.email, so when a booking has no related user row (the Booking.userId relation is nullable and other codepaths already handle missing user data), this method returns no organizer email at all. That makes downstream reschedule logic unable to reliably determine host-vs-guest initiator for those bookings; selecting userPrimaryEmail (or an equivalent fallback) here would avoid dropping host identity.

Useful? React with 👍 / 👎.

Comment on lines +2172 to +2176
OR: [
...(userIds.length > 0 ? [{ userId: { in: userIds } }] : []),
...(userEmails.length > 0
? [{ attendees: { some: { email: { in: userEmails, mode: "insensitive" as const } } } }]
: []),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match bookings by host email when userId is missing

findByUserIdsAndDateRange only matches bookings via userId or attendee email, so organizer-owned bookings with userId = null but a populated userPrimaryEmail are skipped unless the organizer also appears as an attendee. In those cases, busy windows are undercounted and reschedule availability can include invalid slots; adding a userPrimaryEmail email-match branch to this OR would cover that data shape.

Useful? React with 👍 / 👎.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

The PR adds two new query methods to BookingRepository and one to UserRepository, along with comprehensive test coverage. findByUidIncludeAttendeeEmails retrieves booking details by uid with attendee and organizer emails. findByUserIdsAndDateRange queries bookings filtered by status (ACCEPTED/PENDING), date overlap, and either user IDs or attendee emails, with optional uid exclusion. UserRepository.findByEmails bulk-resolves users by email addresses including primary and verified secondary emails. Corresponding unit tests verify the expected Prisma query calls and behavior.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding lookup methods to BookingRepository and UserRepository for guest availability and user lookups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly explains it is Part A of a three-part split, introduces data-access helper methods (findByUidIncludeAttendeeEmails, findByUserIdsAndDateRange, findByEmails), and states it has no call sites yet. It directly relates to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sahitya-chandra
Copy link
Copy Markdown
Member

Thank you for your contribution. This PR is being closed because the linked issue is no longer exists in Cal.diy. blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants