@@ -7,6 +7,9 @@ import { MarkNoShowOutput_2024_04_15 } from "@/ee/bookings/2024-04-15/outputs/ma
77import { PlatformBookingsService } from "@/ee/bookings/shared/platform-bookings.service" ;
88import { sha256Hash , isApiKey , stripApiKey } from "@/lib/api-key" ;
99import { VERSION_2024_04_15 , VERSION_2024_06_11 , VERSION_2024_06_14 } from "@/lib/api-versions" ;
10+ import { InstantBookingCreateService } from "@/lib/services/instant-booking-create.service" ;
11+ import { RecurringBookingService } from "@/lib/services/recurring-booking.service" ;
12+ import { RegularBookingService } from "@/lib/services/regular-booking.service" ;
1013import { ApiKeysRepository } from "@/modules/api-keys/api-keys-repository" ;
1114import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator" ;
1215import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator" ;
@@ -45,11 +48,8 @@ import { v4 as uuidv4 } from "uuid";
4548import { X_CAL_CLIENT_ID , X_CAL_PLATFORM_EMBED } from "@calcom/platform-constants" ;
4649import { BOOKING_READ , SUCCESS_STATUS , BOOKING_WRITE } from "@calcom/platform-constants" ;
4750import {
48- handleNewRecurringBooking ,
49- handleNewBooking ,
5051 BookingResponse ,
5152 HttpError ,
52- handleInstantMeeting ,
5353 handleMarkNoShow ,
5454 getAllUserBookings ,
5555 getBookingInfo ,
@@ -58,6 +58,7 @@ import {
5858 ErrorCode ,
5959} from "@calcom/platform-libraries" ;
6060import { CreationSource } from "@calcom/platform-libraries" ;
61+ import { type InstantBookingCreateResult } from "@calcom/platform-libraries/bookings" ;
6162import {
6263 GetBookingsInput_2024_04_15 ,
6364 CancelBookingInput_2024_04_15 ,
@@ -109,7 +110,10 @@ export class BookingsController_2024_04_15 {
109110 private readonly apiKeyRepository : ApiKeysRepository ,
110111 private readonly platformBookingsService : PlatformBookingsService ,
111112 private readonly usersRepository : UsersRepository ,
112- private readonly usersService : UsersService
113+ private readonly usersService : UsersService ,
114+ private readonly regularBookingService : RegularBookingService ,
115+ private readonly recurringBookingService : RecurringBookingService ,
116+ private readonly instantBookingCreateService : InstantBookingCreateService
113117 ) { }
114118
115119 @Get ( "/" )
@@ -187,17 +191,19 @@ export class BookingsController_2024_04_15 {
187191 const { orgSlug, locationUrl } = body ;
188192 try {
189193 const bookingRequest = await this . createNextApiBookingRequest ( req , oAuthClientId , locationUrl , isEmbed ) ;
190- const booking = await handleNewBooking ( {
194+ const booking = await this . regularBookingService . createBooking ( {
191195 bookingData : bookingRequest . body ,
192- userId : bookingRequest . userId ,
193- hostname : bookingRequest . headers ?. host || "" ,
194- forcedSlug : orgSlug ,
195- platformClientId : bookingRequest . platformClientId ,
196- platformRescheduleUrl : bookingRequest . platformRescheduleUrl ,
197- platformCancelUrl : bookingRequest . platformCancelUrl ,
198- platformBookingUrl : bookingRequest . platformBookingUrl ,
199- platformBookingLocation : bookingRequest . platformBookingLocation ,
200- areCalendarEventsEnabled : bookingRequest . areCalendarEventsEnabled ,
196+ bookingMeta : {
197+ userId : bookingRequest . userId ,
198+ hostname : bookingRequest . headers ?. host || "" ,
199+ forcedSlug : orgSlug ,
200+ platformClientId : bookingRequest . platformClientId ,
201+ platformRescheduleUrl : bookingRequest . platformRescheduleUrl ,
202+ platformCancelUrl : bookingRequest . platformCancelUrl ,
203+ platformBookingUrl : bookingRequest . platformBookingUrl ,
204+ platformBookingLocation : bookingRequest . platformBookingLocation ,
205+ areCalendarEventsEnabled : bookingRequest . areCalendarEventsEnabled ,
206+ } ,
201207 } ) ;
202208 if ( booking . userId && booking . uid && booking . startTime ) {
203209 void ( await this . billingService . increaseUsageByUserId ( booking . userId , {
@@ -315,15 +321,17 @@ export class BookingsController_2024_04_15 {
315321
316322 const bookingRequest = await this . createNextApiBookingRequest ( req , oAuthClientId , undefined , isEmbed ) ;
317323
318- const createdBookings : BookingResponse [ ] = await handleNewRecurringBooking ( {
324+ const createdBookings : BookingResponse [ ] = await this . recurringBookingService . createBooking ( {
319325 bookingData : bookingRequest . body ,
320- userId : bookingRequest . userId ,
321- hostname : bookingRequest . headers ?. host || "" ,
322- platformClientId : bookingRequest . platformClientId ,
323- platformRescheduleUrl : bookingRequest . platformRescheduleUrl ,
324- platformCancelUrl : bookingRequest . platformCancelUrl ,
325- platformBookingUrl : bookingRequest . platformBookingUrl ,
326- platformBookingLocation : bookingRequest . platformBookingLocation ,
326+ bookingMeta : {
327+ userId : bookingRequest . userId ,
328+ hostname : bookingRequest . headers ?. host || "" ,
329+ platformClientId : bookingRequest . platformClientId ,
330+ platformRescheduleUrl : bookingRequest . platformRescheduleUrl ,
331+ platformCancelUrl : bookingRequest . platformCancelUrl ,
332+ platformBookingUrl : bookingRequest . platformBookingUrl ,
333+ platformBookingLocation : bookingRequest . platformBookingLocation ,
334+ } ,
327335 } ) ;
328336
329337 createdBookings . forEach ( async ( booking ) => {
@@ -351,14 +359,15 @@ export class BookingsController_2024_04_15 {
351359 @Body ( ) body : CreateBookingInput_2024_04_15 ,
352360 @Headers ( X_CAL_CLIENT_ID ) clientId ?: string ,
353361 @Headers ( X_CAL_PLATFORM_EMBED ) isEmbed ?: string
354- ) : Promise < ApiResponse < Awaited < ReturnType < typeof handleInstantMeeting > > > > {
362+ ) : Promise < ApiResponse < InstantBookingCreateResult > > {
355363 const oAuthClientId =
356364 clientId ?. toString ( ) || ( await this . getOAuthClientIdFromEventType ( body . eventTypeId ) ) ;
357365 req . userId = ( await this . getOwnerId ( req ) ) ?? - 1 ;
358366 try {
359- const instantMeeting = await handleInstantMeeting (
360- await this . createNextApiBookingRequest ( req , oAuthClientId , undefined , isEmbed )
361- ) ;
367+ const bookingReq = await this . createNextApiBookingRequest ( req , oAuthClientId , undefined , isEmbed ) ;
368+ const instantMeeting = await this . instantBookingCreateService . createBooking ( {
369+ bookingData : bookingReq . body ,
370+ } ) ;
362371
363372 if ( instantMeeting . userId && instantMeeting . bookingUid ) {
364373 const now = new Date ( ) ;
0 commit comments