chore: [Booking Flow Refactor - 4] Add BookingDataPreparationService#24022
chore: [Booking Flow Refactor - 4] Add BookingDataPreparationService#24022hariombalhara wants to merge 16 commits intomainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
de2c60a to
d360284
Compare
3edada1 to
bdc1064
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
bdc1064 to
7500777
Compare
d360284 to
68982ee
Compare
7500777 to
eeb29c8
Compare
68982ee to
9ba3f1d
Compare
…ataPreparationService - Reset BookingRepository.ts to main version and add countActiveBookingsForEventType and findActiveBookingsForEventType methods - Reset UserRepository.ts to main version and add findVerifiedUserByEmail method - Update checkIfBookerEmailIsBlocked.ts to use userRepository instead of direct Prisma calls - Update checkActiveBookingsLimitForBooker.ts to use bookingRepository instead of direct Prisma calls Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
…e and RegularBookingService - Fix verifyCodeUnAuthenticated import path in BookingDataPreparationService.ts - Add missing isReschedule parameter to checkIfBookerEmailIsBlocked call - Fix useCacheIfEnabled to use default value instead of non-existent _shouldServeCache property - Fix CacheService import to use CalendarCacheService from calendar-cache-sql - Fix getAllWorkflowsFromEventType import path to use @calcom/features/ee/workflows/lib Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
The BookingDataPreparationService integration into RegularBookingService.ts will be done in a follow-up PR. This PR focuses on: - Adding the BookingDataPreparationService class and tests - Adding repository methods for booking data preparation - Updating helper functions to use repository pattern Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
The BookingDataPreparationService can work independently without modifying the existing booking flow types. The integration into RegularBookingService.ts will be done in a follow-up PR. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Reset API v2 files, test files, and other files that were incorrectly modified in this PR. The PR should only contain BookingDataPreparationService and its supporting repository methods. Also fixed lint warnings in handleSeats.test.ts by prefixing unused variables with underscore. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
- Reverted booking-validations.integration-test.ts back to booking-validations.test.ts - Reset editLocation.handler.ts to main version (removed console.log change) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
- Update checkIfBookerEmailIsBlocked to use UserRepository instead of direct Prisma - Update checkActiveBookingsLimitForBooker to use BookingRepository instead of direct Prisma - Update RegularBookingService to pass repositories to helper functions - Add BookingDataPreparationService as dependency in IBookingServiceDependencies - Extend BookingFlowConfig type with additional properties Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
…ncies (not yet integrated) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Devin AI is resolving merge conflictsThis PR has merge conflicts with the Devin will:
If you prefer to resolve conflicts manually, you can close the Devin session and handle it yourself. |
…-service Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
…larBookingService Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
… for API v2 compatibility Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

What does this PR do?
This PR extracts booking preparation logic into a dedicated
BookingDataPreparationServiceas part 4 of the booking flow refactor series. The main changes include:BookingDataPreparationService: Centralizes all booking data preparation, validation, transformation, and enrichment logic into a single testable service classBookingRepositoryandUserRepositoryto abstract Prisma queries used during preparationcheckIfBookerEmailIsBlockedandcheckActiveBookingsLimitForBookerto use repository pattern instead of direct Prisma callsThe service handles:
This is a pure refactoring - no functional behavior changes, just improved code organization and testability.
Updates Since Last Revision
Latest changes (DI module + API v2 integration):
BookingDataPreparationService.module.tswith proper DI wiring usingbindModuleToClassOnTokenBOOKING_DATA_PREPARATION_SERVICE,BOOKING_DATA_PREPARATION_SERVICE_MODULE) totokens.tsRegularBookingService.module.tsto includebookingDataPreparationServicedependencyapps/api/v2/src/lib/services/booking-data-preparation.service.ts)regular-booking.service.tsto inject and passBookingDataPreparationServiceregular-booking.module.tsto include the new service providerBookingDataPreparationServicefrom@calcom/platform-libraries/bookingsBookingDataPreparationServiceto useLogger<unknown>type from tslog for API v2 compatibilityPrevious changes (merge conflict resolution + interface update):
bookingDataPreparationService: BookingDataPreparationServicetoIBookingServiceDependenciesinterfacefindActiveBookingsForEventTyperepository method to includebookingSeatselection for seated eventsRepository Methods
BookingRepository:
countActiveBookingsForEventType: Counts active bookings for a booker by emailfindActiveBookingsForEventType: Finds active bookings with ordering and includesbookingSeatfor seated eventsUserRepository:
findVerifiedUserByEmail: Finds verified users checking both primary and secondary emailsVisual Demo
N/A - This is a pure refactoring PR with no UI changes.
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Unit Tests
Integration Testing
Run the full booking flow to ensure preparation still works:
Human Review Checklist
Critical areas to review:
API v2 Logger type cast (HIGH PRIORITY):
apps/api/v2/src/lib/services/booking-data-preparation.service.tsusesbridgeLogger as unknown as TsLogger<unknown>BookingDataPreparationService(currentlywarn,info)Repository pattern migration (HIGH PRIORITY):
checkIfBookerEmailIsBlockednow requiresuserRepositoryparameter - verify all callers are updatedcheckActiveBookingsLimitForBookernow requiresbookingRepositoryparameter - verify all callers are updatedRepository query equivalence (HIGH PRIORITY):
BookingRepository.countActiveBookingsForEventType- Does it correctly count active bookings?BookingRepository.findActiveBookingsForEventType- Does ordering, limit, andbookingSeatselection work correctly?UserRepository.findVerifiedUserByEmail- Does it check both primary and secondary emails correctly?DI wiring completeness:
BookingDataPreparationService.module.tscorrectly wires all dependencies (log, bookingRepository, userRepository)RegularBookingService.module.tsincludes the newbookingDataPreparationServicedependencyNotes
RegularBookingService.handler()will come in a follow-up PRLink to Devin run: https://app.devin.ai/sessions/1f56530a5ce1411894caca3c387d5e64
Requested by: hariom@cal.com (@hariombalhara)