fix: confirm booking doesn't respect minimum booking notice (#14577)

Signed-off-by: Abhiuday <contact.abhiuday@gmail.com>
This commit is contained in:
Abhiuday Gupta
2024-04-26 11:58:11 -04:00
committed by GitHub
parent ab26481738
commit fc16ec59d3
2 changed files with 30 additions and 12 deletions
@@ -15,9 +15,9 @@ import processExternalId from "@calcom/app-store/_utils/calendars/processExterna
import { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_metadata";
import type { LocationObject } from "@calcom/app-store/locations";
import {
getLocationValueForDB,
MeetLocationType,
OrganizerDefaultConferencingAppType,
getLocationValueForDB,
} from "@calcom/app-store/locations";
import type { EventTypeAppsList } from "@calcom/app-store/utils";
import { getAppFromSlug } from "@calcom/app-store/utils";
@@ -54,8 +54,12 @@ import { getFullName } from "@calcom/features/form-builder/utils";
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";
import { parseBookingLimit, parseDurationLimit } from "@calcom/lib";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import {
isPrismaObjOrUndefined,
parseBookingLimit,
parseDurationLimit,
parseRecurringEvent,
} from "@calcom/lib";
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
import { ErrorCode } from "@calcom/lib/errorCodes";
@@ -80,9 +84,9 @@ import type { BookingReference } from "@calcom/prisma/client";
import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import {
EventTypeMetaDataSchema,
bookingCreateSchemaLegacyPropsForApi,
customInputSchema,
EventTypeMetaDataSchema,
userMetadata as userMetadataSchema,
} from "@calcom/prisma/zod-utils";
import type {
@@ -193,6 +197,7 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
lockTimeZoneToggleOnBookingPage: true,
requiresConfirmation: true,
requiresBookerEmailVerification: true,
minimumBookingNotice: true,
userId: true,
price: true,
currency: true,
@@ -701,6 +706,7 @@ async function createBooking({
newBookingData.recurringEventId = originalRescheduledBooking.recurringEventId;
}
}
const createBookingObj = {
include: {
user: {
@@ -1008,13 +1014,17 @@ async function handler(
let timeOutOfBounds = false;
try {
timeOutOfBounds = isOutOfBounds(reqBody.start, {
periodType: eventType.periodType,
periodDays: eventType.periodDays,
periodEndDate: eventType.periodEndDate,
periodStartDate: eventType.periodStartDate,
periodCountCalendarDays: eventType.periodCountCalendarDays,
});
timeOutOfBounds = isOutOfBounds(
reqBody.start,
{
periodType: eventType.periodType,
periodDays: eventType.periodDays,
periodEndDate: eventType.periodEndDate,
periodStartDate: eventType.periodStartDate,
periodCountCalendarDays: eventType.periodCountCalendarDays,
},
eventType.minimumBookingNotice
);
} catch (error) {
loggerWithEventDetails.warn({
message: "NewBooking: Unable set timeOutOfBounds. Using false. ",
+9 -1
View File
@@ -28,13 +28,21 @@ function isOutOfBounds(
}: Pick<
EventType,
"periodType" | "periodDays" | "periodCountCalendarDays" | "periodStartDate" | "periodEndDate"
>
>,
minimumBookingNotice?: number
) {
const date = dayjs(time);
guardAgainstBookingInThePast(date.toDate());
periodDays = periodDays || 0;
if (minimumBookingNotice) {
const minimumBookingStartDate = dayjs().add(minimumBookingNotice, "minutes");
if (date.isBefore(minimumBookingStartDate)) {
return true;
}
}
switch (periodType) {
case PeriodType.ROLLING: {
const periodRollingEndDay = periodCountCalendarDays