Files
cal.diy/apps/web/pages/api/book/recurring-event.ts
T
Hariom BalharaandDevin AI 75d611c2e8 chore: Integrate creation/rescheduling booking audit for Recurring/regular booking/seated bookings (#26046)
* Integrate creation/rescheduling booking audit

* fix: add missing hostUserUuid to booking audit test data

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* fix-ci

* feat: enhance booking audit with seat reference

- Added support for seat reference in booking audit actions.
- Updated localization for booking creation to include seat information.
- Modified relevant services to pass attendee seat ID during booking creation.

* fix: update test data to match schema requirements

- Add seatReferenceUid: null to default mock audit log data
- Add seatReferenceUid: null to multiple audit logs test case
- Convert SEAT_RESCHEDULED test data to use numeric timestamps instead of ISO strings

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* Allow nullish seatReferenceUid

* feat: enhance booking audit to support rescheduledBy information

- Updated booking audit actions to include rescheduledBy details, allowing tracking of who rescheduled a booking.
- Refactored related services to accommodate the new rescheduledBy parameter in booking events.
- Adjusted type definitions and function signatures to reflect the changes in the booking audit context.

* Avoid possible run time issue

* Fix imoport path

* fix failing test due to merge from main\

* Pass useruuid

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-01-13 13:16:16 +00:00

65 lines
2.2 KiB
TypeScript

import type { NextApiRequest } from "next";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getRecurringBookingService } from "@calcom/features/bookings/di/RecurringBookingService.container";
import type { BookingResponse } from "@calcom/features/bookings/types";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import getIP from "@calcom/lib/getIP";
import { piiHasher } from "@calcom/lib/server/PiiHasher";
import { checkCfTurnstileToken } from "@calcom/lib/server/checkCfTurnstileToken";
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.
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") {
await checkCfTurnstileToken({
token: req.body[0]["cfToken"] as string,
remoteIp: userIp,
});
}
await checkRateLimitAndThrowError({
rateLimitingType: "core",
identifier: `createRecurringBooking:${piiHasher.hash(userIp)}`,
});
const session = await getServerSession({ req });
/* To mimic API behavior and comply with types */
const recurringBookingService = getRecurringBookingService();
const createdBookings: BookingResponse[] = await recurringBookingService.createBooking({
bookingData: req.body,
bookingMeta: {
userId: session?.user?.id || -1,
platformClientId: req.platformClientId,
platformCancelUrl: req.platformCancelUrl,
platformBookingUrl: req.platformBookingUrl,
platformRescheduleUrl: req.platformRescheduleUrl,
platformBookingLocation: req.platformBookingLocation,
noEmail: req.noEmail,
},
creationSource: "WEBAPP",
});
return createdBookings;
}
export const handleRecurringEventBooking = handler;
export default defaultResponder(handler);