-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: handleNewBooking #4 #15673
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
47cb39c
refactor: handleNewBooking #3
Udit-takkar 619f54e
refactor: create booking factor
Udit-takkar 717084b
refactor: handleNewBooking
Udit-takkar 801d1c8
refactor: seats and rescheduleUId
Udit-takkar 9fbec20
chore: remove comment
Udit-takkar c4e4278
fix: type err
Udit-takkar 03d7dd7
chore: add missing statement
Udit-takkar 0784208
chore: use less params and other improvements
Udit-takkar 2a92ce6
chore: name
Udit-takkar 1e7e991
chore: improvement
Udit-takkar 7128e11
fix: type err
Udit-takkar d4586c9
Typo fix
joeauyeung 1f5eefa
chore: fix type err
Udit-takkar fb1bafe
refactor: more readable
Udit-takkar 074b0b2
refactor: improve code
Udit-takkar a0fc036
Merge branch 'main' into refactor/handleNewBooking-4
joeauyeung 7380a83
Merge branch 'main' into refactor/handleNewBooking-4
alishaz-polymath 736e4fa
Merge branch 'main' into refactor/handleNewBooking-4
Udit-takkar 6626cb7
fix: conflicts
Udit-takkar 62ac286
Merge branch 'main' into refactor/handleNewBooking-4
joeauyeung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
packages/features/bookings/lib/handleNewBooking/addVideoCallDataToEvent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { BookingReference } from "@calcom/prisma/client"; | ||
import type { CalendarEvent } from "@calcom/types/Calendar"; | ||
|
||
/** Updates the evt object with video call data found from booking references | ||
* | ||
* @param bookingReferences | ||
* @param evt | ||
* | ||
* @returns updated evt with video call data | ||
*/ | ||
export const addVideoCallDataToEvent = (bookingReferences: BookingReference[], evt: CalendarEvent) => { | ||
const videoCallReference = bookingReferences.find((reference) => reference.type.includes("_video")); | ||
|
||
if (videoCallReference) { | ||
evt.videoCallData = { | ||
type: videoCallReference.type, | ||
id: videoCallReference.meetingId, | ||
password: videoCallReference?.meetingPassword, | ||
url: videoCallReference.meetingUrl, | ||
}; | ||
} | ||
|
||
return evt; | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import dayjs from "@calcom/dayjs"; | ||
import { checkBookingLimits, checkDurationLimits } from "@calcom/lib/server"; | ||
import type { IntervalLimit } from "@calcom/types/Calendar"; | ||
|
||
import type { NewBookingEventType } from "./types"; | ||
|
||
type EventType = Pick<NewBookingEventType, "bookingLimits" | "durationLimits" | "id" | "schedule">; | ||
|
||
type InputProps = { | ||
eventType: EventType; | ||
reqBodyStart: string; | ||
reqBodyRescheduleUid?: string; | ||
}; | ||
|
||
export const checkBookingAndDurationLimits = async ({ | ||
eventType, | ||
reqBodyStart, | ||
reqBodyRescheduleUid, | ||
}: InputProps) => { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(eventType, "bookingLimits") || | ||
Object.prototype.hasOwnProperty.call(eventType, "durationLimits") | ||
) { | ||
const startAsDate = dayjs(reqBodyStart).toDate(); | ||
if (eventType.bookingLimits && Object.keys(eventType.bookingLimits).length > 0) { | ||
await checkBookingLimits( | ||
eventType.bookingLimits as IntervalLimit, | ||
startAsDate, | ||
eventType.id, | ||
reqBodyRescheduleUid, | ||
eventType.schedule?.timeZone | ||
); | ||
} | ||
if (eventType.durationLimits) { | ||
await checkDurationLimits( | ||
eventType.durationLimits as IntervalLimit, | ||
startAsDate, | ||
eventType.id, | ||
reqBodyRescheduleUid | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/features/bookings/lib/handleNewBooking/getCustomInputsResponses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type z from "zod"; | ||
|
||
import { slugify } from "@calcom/lib/slugify"; | ||
import type { bookingCreateSchemaLegacyPropsForApi } from "@calcom/prisma/zod-utils"; | ||
import type { CalendarEvent } from "@calcom/types/Calendar"; | ||
|
||
import type { getEventTypeResponse } from "./types"; | ||
|
||
type CustomInputs = z.infer<typeof bookingCreateSchemaLegacyPropsForApi>["customInputs"]; | ||
|
||
type RequestBody = { | ||
responses?: Record<string, object>; | ||
customInputs?: CustomInputs; | ||
}; | ||
|
||
function mapCustomInputs( | ||
customInputs: { label: string; value: CustomInputs[number]["value"] }[] | ||
): Record<string, CustomInputs[number]["value"]> { | ||
return customInputs.reduce((acc, { label, value }) => { | ||
acc[label] = value; | ||
return acc; | ||
}, {} as Record<string, CustomInputs[number]["value"]>); | ||
} | ||
|
||
function mapResponsesToCustomInputs( | ||
responses: Record<string, object>, | ||
eventTypeCustomInputs: getEventTypeResponse["customInputs"] | ||
): NonNullable<CalendarEvent["customInputs"]> { | ||
// Backward Compatibility: Map new `responses` to old `customInputs` format so that webhooks can still receive same values. | ||
return Object.entries(responses).reduce((acc, [fieldName, fieldValue]) => { | ||
const foundInput = eventTypeCustomInputs.find((input) => slugify(input.label) === fieldName); | ||
if (foundInput) { | ||
acc[foundInput.label] = fieldValue; | ||
} | ||
return acc; | ||
}, {} as NonNullable<CalendarEvent["customInputs"]>); | ||
} | ||
Comment on lines
+30
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
export function getCustomInputsResponses( | ||
reqBody: RequestBody, | ||
eventTypeCustomInputs: getEventTypeResponse["customInputs"] | ||
): NonNullable<CalendarEvent["customInputs"]> { | ||
if (reqBody.customInputs && reqBody.customInputs.length > 0) { | ||
return mapCustomInputs(reqBody.customInputs); | ||
} | ||
|
||
const responses = reqBody.responses || {}; | ||
return mapResponsesToCustomInputs(responses, eventTypeCustomInputs); | ||
Comment on lines
+39
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored this function |
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check both booking and duration limits.