fix: confirm booking doesn't respect minimum booking notice (#14577)
Signed-off-by: Abhiuday <[email protected]>
This commit is contained in:
1 parent
ab26481738
commit
fc16ec59d3
2 files changed
+30
-12
No files matched your search
@@ -15,9 +15,9 @@ import processExternalId from "@calcom/app-store/_utils/calendars/processExterna
|
|||||||
import { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_metadata";
|
import { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_metadata";
|
||||||
import type { LocationObject } from "@calcom/app-store/locations";
|
import type { LocationObject } from "@calcom/app-store/locations";
|
||||||
import {
|
import {
|
||||||
getLocationValueForDB,
|
|
||||||
MeetLocationType,
|
MeetLocationType,
|
||||||
OrganizerDefaultConferencingAppType,
|
OrganizerDefaultConferencingAppType,
|
||||||
|
getLocationValueForDB,
|
||||||
} from "@calcom/app-store/locations";
|
} from "@calcom/app-store/locations";
|
||||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||||
import { getAppFromSlug } 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 type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||||
import { parseBookingLimit, parseDurationLimit } from "@calcom/lib";
|
import {
|
||||||
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
|
isPrismaObjOrUndefined,
|
||||||
|
parseBookingLimit,
|
||||||
|
parseDurationLimit,
|
||||||
|
parseRecurringEvent,
|
||||||
|
} from "@calcom/lib";
|
||||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||||
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
|
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
|
||||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
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 { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||||
import {
|
import {
|
||||||
|
EventTypeMetaDataSchema,
|
||||||
bookingCreateSchemaLegacyPropsForApi,
|
bookingCreateSchemaLegacyPropsForApi,
|
||||||
customInputSchema,
|
customInputSchema,
|
||||||
EventTypeMetaDataSchema,
|
|
||||||
userMetadata as userMetadataSchema,
|
userMetadata as userMetadataSchema,
|
||||||
} from "@calcom/prisma/zod-utils";
|
} from "@calcom/prisma/zod-utils";
|
||||||
import type {
|
import type {
|
||||||
@@ -193,6 +197,7 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
|
|||||||
lockTimeZoneToggleOnBookingPage: true,
|
lockTimeZoneToggleOnBookingPage: true,
|
||||||
requiresConfirmation: true,
|
requiresConfirmation: true,
|
||||||
requiresBookerEmailVerification: true,
|
requiresBookerEmailVerification: true,
|
||||||
|
minimumBookingNotice: true,
|
||||||
userId: true,
|
userId: true,
|
||||||
price: true,
|
price: true,
|
||||||
currency: true,
|
currency: true,
|
||||||
@@ -701,6 +706,7 @@ async function createBooking({
|
|||||||
newBookingData.recurringEventId = originalRescheduledBooking.recurringEventId;
|
newBookingData.recurringEventId = originalRescheduledBooking.recurringEventId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createBookingObj = {
|
const createBookingObj = {
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
@@ -1008,13 +1014,17 @@ async function handler(
|
|||||||
|
|
||||||
let timeOutOfBounds = false;
|
let timeOutOfBounds = false;
|
||||||
try {
|
try {
|
||||||
timeOutOfBounds = isOutOfBounds(reqBody.start, {
|
timeOutOfBounds = isOutOfBounds(
|
||||||
periodType: eventType.periodType,
|
reqBody.start,
|
||||||
periodDays: eventType.periodDays,
|
{
|
||||||
periodEndDate: eventType.periodEndDate,
|
periodType: eventType.periodType,
|
||||||
periodStartDate: eventType.periodStartDate,
|
periodDays: eventType.periodDays,
|
||||||
periodCountCalendarDays: eventType.periodCountCalendarDays,
|
periodEndDate: eventType.periodEndDate,
|
||||||
});
|
periodStartDate: eventType.periodStartDate,
|
||||||
|
periodCountCalendarDays: eventType.periodCountCalendarDays,
|
||||||
|
},
|
||||||
|
eventType.minimumBookingNotice
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loggerWithEventDetails.warn({
|
loggerWithEventDetails.warn({
|
||||||
message: "NewBooking: Unable set timeOutOfBounds. Using false. ",
|
message: "NewBooking: Unable set timeOutOfBounds. Using false. ",
|
||||||
|
|||||||
@@ -28,13 +28,21 @@ function isOutOfBounds(
|
|||||||
}: Pick<
|
}: Pick<
|
||||||
EventType,
|
EventType,
|
||||||
"periodType" | "periodDays" | "periodCountCalendarDays" | "periodStartDate" | "periodEndDate"
|
"periodType" | "periodDays" | "periodCountCalendarDays" | "periodStartDate" | "periodEndDate"
|
||||||
>
|
>,
|
||||||
|
minimumBookingNotice?: number
|
||||||
) {
|
) {
|
||||||
const date = dayjs(time);
|
const date = dayjs(time);
|
||||||
guardAgainstBookingInThePast(date.toDate());
|
guardAgainstBookingInThePast(date.toDate());
|
||||||
|
|
||||||
periodDays = periodDays || 0;
|
periodDays = periodDays || 0;
|
||||||
|
|
||||||
|
if (minimumBookingNotice) {
|
||||||
|
const minimumBookingStartDate = dayjs().add(minimumBookingNotice, "minutes");
|
||||||
|
if (date.isBefore(minimumBookingStartDate)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (periodType) {
|
switch (periodType) {
|
||||||
case PeriodType.ROLLING: {
|
case PeriodType.ROLLING: {
|
||||||
const periodRollingEndDay = periodCountCalendarDays
|
const periodRollingEndDay = periodCountCalendarDays
|
||||||
|
|||||||
Reference in new issue
Block a user