Skip to content

fix(daily-webhook): use BookingRepository instead of direct prisma call#29541

Draft
JustSidus wants to merge 2 commits into
calcom:mainfrom
JustSidus:fix/issue-28835-daily-webhook-booking-repo
Draft

fix(daily-webhook): use BookingRepository instead of direct prisma call#29541
JustSidus wants to merge 2 commits into
calcom:mainfrom
JustSidus:fix/issue-28835-daily-webhook-booking-repo

Conversation

@JustSidus

Copy link
Copy Markdown

The getBooking function in daily-webhook/getBooking.ts had a // TODO: use BookingRepository comment and was calling prisma.booking.findUniqueOrThrow directly. This replaces it with a new indByIdForDailyWebhook method on BookingRepository, keeping the same select shape so the return type is unchanged.

Before:
ypescript const booking = await prisma.booking.findUniqueOrThrow({ where: { id: bookingId }, select: { ...bookingMinimalSelect, uid: true, location: true, isRecorded: true, eventTypeId: true, eventType: { ... }, user: { ... }, }, });

After:
ypescript const bookingRepository = new BookingRepository(prisma); const booking = await bookingRepository.findByIdForDailyWebhook(bookingId);

No behavior change - the select is identical, just routed through the repository layer as the TODO requested.

Fixes #28835

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @JustSidus! 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!

@github-actions github-actions Bot added the 🐛 bug Something isn't working label Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR contains three targeted fixes and refactoring changes. A new findByIdForDailyWebhook method was added to BookingRepository to encapsulate booking queries with daily webhook-specific field selections. The getBooking function was refactored to use this new repository method instead of inline Prisma queries. Additionally, a bug in VerifiedResourcesService was corrected where getUserVerifiedPhoneNumber was mistakenly calling the email-based repository method instead of the phone-number variant.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing direct Prisma calls with BookingRepository in the daily-webhook code.
Description check ✅ Passed The description clearly explains the refactoring, provides before/after code examples, and references the resolved issue.
Linked Issues check ✅ Passed The PR fully meets the objective of issue #28835 by replacing the direct Prisma call with a BookingRepository method and removing the TODO comment.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: creating a new repository method and refactoring getBooking to use it, with one unrelated service fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/lib/daily-webhook/getBooking.ts`:
- Around line 10-11: The repository method used by getBooking
(BookingRepository.findByIdForDailyWebhook) currently calls findUniqueOrThrow
which raises a PrismaClientKnownRequestError for missing rows and breaks the
null-check in getBooking; change that repository implementation in
packages/features/bookings/repositories/BookingRepository.ts to use
prisma.findUnique (not findUniqueOrThrow) so it returns null when no booking is
found, preserving the existing null-check in getBooking.ts and allowing
getBooking to throw the intended HttpError 404 with the descriptive message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54291b07-beeb-4113-9b9c-1e59cb71af4f

📥 Commits

Reviewing files that changed from the base of the PR and between 4026669 and 269db08.

📒 Files selected for processing (3)
  • apps/api/v2/src/modules/verified-resources/services/verified-resources.service.ts
  • apps/web/lib/daily-webhook/getBooking.ts
  • packages/features/bookings/repositories/BookingRepository.ts

Comment on lines +10 to +11
const bookingRepository = new BookingRepository(prisma);
const booking = await bookingRepository.findByIdForDailyWebhook(bookingId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Change findUniqueOrThrow to findUnique to preserve error handling behavior.

The new repository method uses findUniqueOrThrow, which throws a PrismaClientKnownRequestError when the booking is not found. This bypasses the null check below (lines 13-25) that throws a specific HttpError with status 404 and a descriptive message.

Impact:

  • Before: Missing booking → HttpError 404 with message "Booking of id X does not exist or does not contain daily video as location"
  • After: Missing booking → PrismaClientKnownRequestError → caught by downstream handler as generic 500 "something went wrong"

This degrades the error response quality for API consumers.

🔧 Proposed fix

In packages/features/bookings/repositories/BookingRepository.ts, change the repository method to use findUnique:

   async findByIdForDailyWebhook(bookingId: number) {
-    return await this.prismaClient.booking.findUniqueOrThrow({
+    return await this.prismaClient.booking.findUnique({
       where: {
         id: bookingId,
       },

This preserves the existing error handling contract where getBooking returns null when not found, then throws the appropriate HttpError.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/lib/daily-webhook/getBooking.ts` around lines 10 - 11, The
repository method used by getBooking (BookingRepository.findByIdForDailyWebhook)
currently calls findUniqueOrThrow which raises a PrismaClientKnownRequestError
for missing rows and breaks the null-check in getBooking; change that repository
implementation in packages/features/bookings/repositories/BookingRepository.ts
to use prisma.findUnique (not findUniqueOrThrow) so it returns null when no
booking is found, preserving the existing null-check in getBooking.ts and
allowing getBooking to throw the intended HttpError 404 with the descriptive
message.


async getUserVerifiedPhoneNumber(userId: number, phoneNumber: string) {
return this.usersVerifiedResourcesRepository.getUserVerifiedEmail(userId, phoneNumber);
return this.usersVerifiedResourcesRepository.getUserVerifiedPhoneNumber(userId, phoneNumber);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JustSidus can you undo this file changes? it's out of scope.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done - removed the out-of-scope file change. The commit now only touches getBooking.ts and BookingRepository.ts.

});
}

async findByIdForDailyWebhook(bookingId: number) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this name is too specific. We might want to reuse somewhere too. Either rename it something that can be reused in future, or use some existing functions!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Renamed to findByIdWithUserAndEventType - more generic and reusable. Also changed findUniqueOrThrow to findUnique to preserve the null-check error handling.

@bandhan-majumder bandhan-majumder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

left some comments!

@bandhan-majumder bandhan-majumder marked this pull request as draft June 11, 2026 04:10
@JustSidus JustSidus force-pushed the fix/issue-28835-daily-webhook-booking-repo branch from 269db08 to c16e130 Compare June 11, 2026 04:22
@JustSidus JustSidus force-pushed the fix/issue-28835-daily-webhook-booking-repo branch from c16e130 to dd41cdd Compare June 11, 2026 21:45
@CLAassistant

CLAassistant commented Jun 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

🐛 bug Something isn't working size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(daily-webhook): prevent direct prisma call and use BookingRepository for finding bookings

3 participants