* refactor handleCancelBooking to not have next request * fix platform v2 function calls * dont fall back to "" if no seat refrence * add missing type from merge * chore: bump platform libraries --------- Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: Lauris Skraucis <lauris.skraucis@gmail.com> Co-authored-by: supalarry <laurisskraucis@gmail.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
|
|
import { cookies, headers } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import handleCancelBooking from "@calcom/features/bookings/lib/handleCancelBooking";
|
|
import { bookingCancelInput } from "@calcom/prisma/zod-utils";
|
|
|
|
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
|
|
|
async function handler(req: NextRequest) {
|
|
let appDirRequestBody;
|
|
try {
|
|
appDirRequestBody = await req.json();
|
|
} catch (error) {
|
|
return NextResponse.json({ success: false, message: "Invalid JSON" }, { status: 400 });
|
|
}
|
|
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
|
const bookingData = bookingCancelInput.parse(appDirRequestBody);
|
|
const result = await handleCancelBooking({
|
|
bookingData,
|
|
userId: session?.user?.id || -1,
|
|
});
|
|
|
|
const statusCode = result.success ? 200 : 400;
|
|
|
|
return NextResponse.json(result, { status: statusCode });
|
|
}
|
|
|
|
export const DELETE = defaultResponderForAppDir(handler);
|
|
export const POST = defaultResponderForAppDir(handler);
|