* migration and init to accept creationSource for new bookings * V1 create booking * V1 user creation * webapp booking + V1 user * user creation in V1, V2 and webapp * booking source V2 and fix for v1 user * fit type * --fix type * add test -- WIP * fix type * fix type * ^ * Need more sleep zzz * -_- * bump libraries platform * adds for v2 recurring booking * fix lint * instant meetings * fix: api v2 creation source * fixup! fix: api v2 creation source * bump libraries * add user * fix test * fixup! fix test * add more source * more source... * fix type & test --1 * fix type & test --2 * typefix * fixup test --------- Co-authored-by: Morgan Vernay <morgan@cal.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";
|
|
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
|
import getIP from "@calcom/lib/getIP";
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
import { checkCfTurnstileToken } from "@calcom/lib/server/checkCfTurnstileToken";
|
|
import { CreationSource } from "@calcom/prisma/enums";
|
|
|
|
async function handler(req: NextApiRequest & { userId?: number }, res: NextApiResponse) {
|
|
const userIp = getIP(req);
|
|
|
|
if (process.env.NEXT_PUBLIC_CLOUDFLARE_USE_TURNSTILE_IN_BOOKER === "1") {
|
|
await checkCfTurnstileToken({
|
|
token: req.body["cfToken"] as string,
|
|
remoteIp: userIp,
|
|
});
|
|
}
|
|
|
|
await checkRateLimitAndThrowError({
|
|
rateLimitingType: "core",
|
|
identifier: userIp,
|
|
});
|
|
|
|
const session = await getServerSession({ req, res });
|
|
/* 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);
|
|
return booking;
|
|
}
|
|
|
|
export default defaultResponder(handler, "/api/book/event");
|