refactor: extract NextRequest from handle new booking (#20082)
* extract NextRequest * update api and tests * booking limits tests * fix more tests to use new approach * update more tests with new format * extract getOrgDomainConfig to not use req * extract req from loadNewUsers and pass in hostname/forcedSlug * fix instant meeting types and hostname fixes * fix handleNewBookingReq * fix type errors in tests * make hostName and forcedSlug optional * fix type err * Revert "fix type err" This reverts commit 9d5de9019d9dafe348c97b876baaa1d0675967e5. * wip fix e2e * fix: add missing headers * migrate handle recurring event and also create tests specific to fn * platform recurringbooking * fix type * hard code types on request object * bump libraries * fixup! bump libraries * fix: accessing host if headers not passed * fix: v2 recurring booking * fix: accessing host if headers not passed * chore: bump platform libraries * fix tests * push * chore: bump libraries * push lock changes * bump libraries --------- Co-authored-by: amrit <iamamrit27@gmail.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Morgan Vernay <morgan@cal.com> Co-authored-by: supalarry <laurisskraucis@gmail.com> Co-authored-by: Lauris Skraucis <lauris.skraucis@gmail.com>
This commit is contained in:
co-authored by
amrit
Morgan
Morgan Vernay
supalarry
Lauris Skraucis
parent
4db3c592e5
commit
417a612aa3
@@ -25,12 +25,17 @@ async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
|
||||
const session = await getServerSession({ req });
|
||||
/* To mimic API behavior and comply with types */
|
||||
req.userId = session?.user?.id || -1;
|
||||
req.body = {
|
||||
...req.body,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
};
|
||||
const booking = await handleNewBooking(req);
|
||||
|
||||
const booking = await handleNewBooking({
|
||||
bookingData: req.body,
|
||||
userId: session?.user?.id || -1,
|
||||
hostname: req.headers.host || "",
|
||||
forcedSlug: req.headers["x-cal-force-slug"] as string | undefined,
|
||||
});
|
||||
return booking;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,22 @@ import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||
|
||||
// @TODO: Didn't look at the contents of this function in order to not break old booking page.
|
||||
|
||||
async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
type PlatformParams = {
|
||||
platformClientId?: string;
|
||||
platformCancelUrl?: string;
|
||||
platformBookingUrl?: string;
|
||||
platformRescheduleUrl?: string;
|
||||
platformBookingLocation?: string;
|
||||
};
|
||||
|
||||
type RequestMeta = {
|
||||
userId?: number;
|
||||
hostname?: string;
|
||||
forcedSlug?: string;
|
||||
noEmail?: boolean;
|
||||
} & PlatformParams;
|
||||
|
||||
async function handler(req: NextApiRequest & RequestMeta) {
|
||||
const userIp = getIP(req);
|
||||
|
||||
if (process.env.NEXT_PUBLIC_CLOUDFLARE_USE_TURNSTILE_IN_BOOKER === "1") {
|
||||
@@ -26,9 +41,17 @@ async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
});
|
||||
const session = await getServerSession({ req });
|
||||
/* To mimic API behavior and comply with types */
|
||||
req.userId = session?.user?.id || -1;
|
||||
|
||||
const createdBookings: BookingResponse[] = await handleNewRecurringBooking(req);
|
||||
const createdBookings: BookingResponse[] = await handleNewRecurringBooking({
|
||||
bookingData: req.body,
|
||||
userId: session?.user?.id || -1,
|
||||
platformClientId: req.platformClientId,
|
||||
platformCancelUrl: req.platformCancelUrl,
|
||||
platformBookingUrl: req.platformBookingUrl,
|
||||
platformRescheduleUrl: req.platformRescheduleUrl,
|
||||
platformBookingLocation: req.platformBookingLocation,
|
||||
noEmail: req.noEmail,
|
||||
});
|
||||
|
||||
return createdBookings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user