fix: circular dependency in handleNewBooking (#19890)
* fix: circular dependency * fix: get orginial scheduled booking * fix: create logger * fix: type err
This commit is contained in:
@@ -91,26 +91,23 @@ import { addVideoCallDataToEvent } from "./handleNewBooking/addVideoCallDataToEv
|
||||
import { checkBookingAndDurationLimits } from "./handleNewBooking/checkBookingAndDurationLimits";
|
||||
import { checkIfBookerEmailIsBlocked } from "./handleNewBooking/checkIfBookerEmailIsBlocked";
|
||||
import { createBooking } from "./handleNewBooking/createBooking";
|
||||
import type { Booking } from "./handleNewBooking/createBooking";
|
||||
import { ensureAvailableUsers } from "./handleNewBooking/ensureAvailableUsers";
|
||||
import { getBookingData } from "./handleNewBooking/getBookingData";
|
||||
import { getCustomInputsResponses } from "./handleNewBooking/getCustomInputsResponses";
|
||||
import { getEventTypesFromDB } from "./handleNewBooking/getEventTypesFromDB";
|
||||
import type { getEventTypeResponse } from "./handleNewBooking/getEventTypesFromDB";
|
||||
import { getLocationValuesForDb } from "./handleNewBooking/getLocationValuesForDb";
|
||||
import { getOriginalRescheduledBooking } from "./handleNewBooking/getOriginalRescheduledBooking";
|
||||
import { getRequiresConfirmationFlags } from "./handleNewBooking/getRequiresConfirmationFlags";
|
||||
import { getSeatedBooking } from "./handleNewBooking/getSeatedBooking";
|
||||
import { getVideoCallDetails } from "./handleNewBooking/getVideoCallDetails";
|
||||
import { handleAppsStatus } from "./handleNewBooking/handleAppsStatus";
|
||||
import { loadAndValidateUsers } from "./handleNewBooking/loadAndValidateUsers";
|
||||
import { createLoggerWithEventDetails } from "./handleNewBooking/logger";
|
||||
import { getOriginalRescheduledBooking } from "./handleNewBooking/originalRescheduledBookingUtils";
|
||||
import type { BookingType } from "./handleNewBooking/originalRescheduledBookingUtils";
|
||||
import { scheduleNoShowTriggers } from "./handleNewBooking/scheduleNoShowTriggers";
|
||||
import type {
|
||||
Booking,
|
||||
BookingType,
|
||||
IEventTypePaymentCredentialType,
|
||||
Invitee,
|
||||
IsFixedAwareUser,
|
||||
} from "./handleNewBooking/types";
|
||||
import type { IEventTypePaymentCredentialType, Invitee, IsFixedAwareUser } from "./handleNewBooking/types";
|
||||
import { validateBookingTimeIsNotOutOfBounds } from "./handleNewBooking/validateBookingTimeIsNotOutOfBounds";
|
||||
import { validateEventLength } from "./handleNewBooking/validateEventLength";
|
||||
import handleSeats from "./handleSeats/handleSeats";
|
||||
@@ -122,16 +119,6 @@ type IsFixedAwareUserWithCredentials = Omit<IsFixedAwareUser, "credentials"> & {
|
||||
credentials: CredentialForCalendarService[];
|
||||
};
|
||||
|
||||
export const createLoggerWithEventDetails = (
|
||||
eventTypeId: number,
|
||||
reqBodyUser: string | string[] | undefined,
|
||||
eventTypeSlug: string | undefined
|
||||
) => {
|
||||
return logger.getSubLogger({
|
||||
prefix: ["book:user", `${eventTypeId}:${reqBodyUser}/${eventTypeSlug}`],
|
||||
});
|
||||
};
|
||||
|
||||
function assertNonEmptyArray<T>(arr: T[]): asserts arr is [T, ...T[]] {
|
||||
if (arr.length === 0) {
|
||||
throw new Error("Array should have at least one item, but it's empty");
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSche
|
||||
import { checkBookingLimits } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
|
||||
import { checkDurationLimits } from "@calcom/lib/intervalLimits/server/checkDurationLimits";
|
||||
|
||||
import type { NewBookingEventType } from "./types";
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
|
||||
type EventType = Pick<NewBookingEventType, "bookingLimits" | "durationLimits" | "id" | "schedule">;
|
||||
|
||||
|
||||
@@ -11,14 +11,11 @@ import type { CreationSource } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { TgetBookingDataSchema } from "../getBookingDataSchema";
|
||||
import type {
|
||||
EventTypeId,
|
||||
AwaitedBookingData,
|
||||
NewBookingEventType,
|
||||
PaymentAppData,
|
||||
OriginalRescheduledBooking,
|
||||
LoadedUsers,
|
||||
} from "./types";
|
||||
import type { AwaitedBookingData, EventTypeId } from "./getBookingData";
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
import type { LoadedUsers } from "./loadUsers";
|
||||
import type { OriginalRescheduledBooking } from "./originalRescheduledBookingUtils";
|
||||
import type { PaymentAppData } from "./types";
|
||||
|
||||
type ReqBodyWithEnd = TgetBookingDataSchema & { end: string };
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
import type { IsFixedAwareUser, BookingType } from "./types";
|
||||
import type { BookingType } from "./originalRescheduledBookingUtils";
|
||||
import type { IsFixedAwareUser } from "./types";
|
||||
|
||||
type DateRange = {
|
||||
start: Dayjs;
|
||||
|
||||
@@ -8,8 +8,8 @@ import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { bookingCreateSchemaLegacyPropsForApi } from "@calcom/prisma/zod/custom/booking";
|
||||
|
||||
import type { TgetBookingDataSchema } from "../getBookingDataSchema";
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
import { handleCustomInputs } from "./handleCustomInputs";
|
||||
import type { getEventTypeResponse } from "./types";
|
||||
|
||||
type ReqBodyWithEnd = TgetBookingDataSchema & { end: string };
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { slugify } from "@calcom/lib/slugify";
|
||||
import type { bookingCreateSchemaLegacyPropsForApi } from "@calcom/prisma/zod/custom/booking";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { getEventTypeResponse } from "./types";
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
|
||||
type CustomInputs = z.infer<typeof bookingCreateSchemaLegacyPropsForApi>["customInputs"];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { LocationObject } from "@calcom/app-store/locations";
|
||||
import { workflowSelect } from "@calcom/ee/workflows/lib/getAllWorkflows";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { parseRecurringEvent } from "@calcom/lib";
|
||||
import type { DefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import { withSelectedCalendars } from "@calcom/lib/server/repository/user";
|
||||
import prisma, { userSelect } from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
@@ -191,3 +192,5 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||
};
|
||||
|
||||
export type getEventTypeResponse = Awaited<ReturnType<typeof getEventTypesFromDB>>;
|
||||
|
||||
export type NewBookingEventType = DefaultEvent | getEventTypeResponse;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
|
||||
import { validateOriginalRescheduledBooking } from "./validateOriginalRescheduledBooking";
|
||||
|
||||
export async function getOriginalRescheduledBooking(uid: string, seatsEventType?: boolean) {
|
||||
const originalBooking = await BookingRepository.findOriginalRescheduledBooking(uid, seatsEventType);
|
||||
validateOriginalRescheduledBooking(originalBooking);
|
||||
|
||||
return originalBooking;
|
||||
}
|
||||
|
||||
export type BookingType = Prisma.PromiseReturnType<typeof getOriginalRescheduledBooking>;
|
||||
|
||||
export type OriginalRescheduledBooking = Awaited<ReturnType<typeof getOriginalRescheduledBooking>>;
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { AdditionalInformation, AppsStatus } from "@calcom/types/Calendar";
|
||||
import type { EventResult } from "@calcom/types/EventManager";
|
||||
|
||||
import type { ReqAppsStatus, Booking } from "./types";
|
||||
import type { Booking } from "./createBooking";
|
||||
import type { ReqAppsStatus } from "./getBookingData";
|
||||
|
||||
export function handleAppsStatus(
|
||||
results: EventResult<AdditionalInformation>[],
|
||||
|
||||
@@ -16,8 +16,8 @@ import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
import { loadUsers } from "./loadUsers";
|
||||
import type { NewBookingEventType } from "./types";
|
||||
|
||||
type Users = (Awaited<ReturnType<typeof loadUsers>>[number] & {
|
||||
isFixed?: boolean;
|
||||
|
||||
@@ -14,7 +14,7 @@ import { withSelectedCalendars, UserRepository } from "@calcom/lib/server/reposi
|
||||
import prisma, { userSelect } from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import type { NewBookingEventType } from "./types";
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[loadUsers]:handleNewBooking "] });
|
||||
|
||||
@@ -135,3 +135,8 @@ export const findUsersByUsername = async ({
|
||||
};
|
||||
|
||||
export type LoadedUsers = Awaited<ReturnType<typeof loadUsers>>;
|
||||
|
||||
export type OrganizerUser = LoadedUsers[number] & {
|
||||
isFixed?: boolean;
|
||||
metadata?: Prisma.JsonValue;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
|
||||
export const createLoggerWithEventDetails = (
|
||||
eventTypeId: number,
|
||||
reqBodyUser: string | string[] | undefined,
|
||||
eventTypeSlug: string | undefined
|
||||
) => {
|
||||
return logger.getSubLogger({
|
||||
prefix: ["book:user", `${eventTypeId}:${reqBodyUser}/${eventTypeSlug}`],
|
||||
});
|
||||
};
|
||||
+14
-2
@@ -1,9 +1,10 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
import { type OriginalRescheduledBooking } from "./getOriginalRescheduledBooking";
|
||||
|
||||
export const validateOriginalRescheduledBooking = async (
|
||||
originalRescheduledBooking: OriginalRescheduledBooking
|
||||
) => {
|
||||
@@ -18,3 +19,14 @@ export const validateOriginalRescheduledBooking = async (
|
||||
throw new HttpError({ statusCode: 403, message: ErrorCode.CancelledBookingsCannotBeRescheduled });
|
||||
}
|
||||
};
|
||||
|
||||
export async function getOriginalRescheduledBooking(uid: string, seatsEventType?: boolean) {
|
||||
const originalBooking = await BookingRepository.findOriginalRescheduledBooking(uid, seatsEventType);
|
||||
validateOriginalRescheduledBooking(originalBooking);
|
||||
|
||||
return originalBooking;
|
||||
}
|
||||
|
||||
export type BookingType = Prisma.PromiseReturnType<typeof getOriginalRescheduledBooking>;
|
||||
|
||||
export type OriginalRescheduledBooking = Awaited<ReturnType<typeof getOriginalRescheduledBooking>>;
|
||||
@@ -3,34 +3,13 @@ import type { Prisma } from "@prisma/client";
|
||||
import type { TFunction } from "next-i18next";
|
||||
|
||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||
import type { DefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import type { PaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import type { userSelect } from "@calcom/prisma";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
import type { Booking } from "./createBooking";
|
||||
import type {
|
||||
AwaitedBookingData,
|
||||
RescheduleReason,
|
||||
NoEmail,
|
||||
AdditionalNotes,
|
||||
ReqAppsStatus,
|
||||
SmsReminderNumber,
|
||||
EventTypeId,
|
||||
ReqBodyMetadata,
|
||||
} from "./getBookingData";
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
import type { BookingType, OriginalRescheduledBooking } from "./getOriginalRescheduledBooking";
|
||||
import type { LoadedUsers } from "./loadUsers";
|
||||
|
||||
type User = Omit<Prisma.UserGetPayload<typeof userSelect>, "selectedCalendars">;
|
||||
|
||||
export type OrganizerUser = LoadedUsers[number] & {
|
||||
isFixed?: boolean;
|
||||
metadata?: Prisma.JsonValue;
|
||||
};
|
||||
|
||||
export type Invitee = {
|
||||
email: string;
|
||||
name: string;
|
||||
@@ -63,21 +42,4 @@ export type IsFixedAwareUser = User & {
|
||||
allSelectedCalendars: SelectedCalendar[];
|
||||
};
|
||||
|
||||
export type NewBookingEventType = DefaultEvent | getEventTypeResponse;
|
||||
|
||||
export type {
|
||||
AwaitedBookingData,
|
||||
RescheduleReason,
|
||||
NoEmail,
|
||||
AdditionalNotes,
|
||||
ReqAppsStatus,
|
||||
SmsReminderNumber,
|
||||
EventTypeId,
|
||||
ReqBodyMetadata,
|
||||
PaymentAppData,
|
||||
BookingType,
|
||||
Booking,
|
||||
OriginalRescheduledBooking,
|
||||
LoadedUsers,
|
||||
getEventTypeResponse,
|
||||
};
|
||||
export type { PaymentAppData };
|
||||
|
||||
@@ -8,7 +8,7 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
import { createLoggerWithEventDetails } from "../handleNewBooking";
|
||||
import { createLoggerWithEventDetails } from "../handleNewBooking/logger";
|
||||
import createNewSeat from "./create/createNewSeat";
|
||||
import rescheduleSeatedBooking from "./reschedule/rescheduleSeatedBooking";
|
||||
import type { NewSeatedBookingObject, SeatedBooking, HandleSeatsResultBooking } from "./types";
|
||||
|
||||
@@ -9,7 +9,7 @@ import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { OriginalRescheduledBooking } from "../../handleNewBooking/types";
|
||||
import type { OriginalRescheduledBooking } from "../../handleNewBooking/originalRescheduledBookingUtils";
|
||||
|
||||
/* Check if the original booking has no more attendees, if so delete the booking
|
||||
and any calendar or video integrations */
|
||||
|
||||
+1
-1
@@ -9,9 +9,9 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking";
|
||||
import { addVideoCallDataToEvent } from "../../../handleNewBooking/addVideoCallDataToEvent";
|
||||
import { findBookingQuery } from "../../../handleNewBooking/findBookingQuery";
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking/logger";
|
||||
import type { SeatedBooking, RescheduleSeatedBookingObject, NewTimeSlotBooking } from "../../types";
|
||||
|
||||
const combineTwoSeatedBookings = async (
|
||||
|
||||
+2
-2
@@ -6,11 +6,11 @@ import type EventManager from "@calcom/lib/EventManager";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { AdditionalInformation, AppsStatus } from "@calcom/types/Calendar";
|
||||
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking";
|
||||
import { addVideoCallDataToEvent } from "../../../handleNewBooking/addVideoCallDataToEvent";
|
||||
import type { Booking } from "../../../handleNewBooking/createBooking";
|
||||
import { findBookingQuery } from "../../../handleNewBooking/findBookingQuery";
|
||||
import { handleAppsStatus } from "../../../handleNewBooking/handleAppsStatus";
|
||||
import type { Booking } from "../../../handleNewBooking/types";
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking/logger";
|
||||
import type { SeatedBooking, RescheduleSeatedBookingObject } from "../../types";
|
||||
|
||||
const moveSeatedBookingToNewTimeSlot = async (
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import type EventManager from "@calcom/lib/EventManager";
|
||||
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking";
|
||||
import type { createLoggerWithEventDetails } from "../../../handleNewBooking/logger";
|
||||
import type {
|
||||
NewTimeSlotBooking,
|
||||
SeatedBooking,
|
||||
|
||||
@@ -7,7 +7,7 @@ import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { Person } from "@calcom/types/Calendar";
|
||||
|
||||
import type { createLoggerWithEventDetails } from "../../handleNewBooking";
|
||||
import type { createLoggerWithEventDetails } from "../../handleNewBooking/logger";
|
||||
import type {
|
||||
HandleSeatsResultBooking,
|
||||
SeatedBooking,
|
||||
|
||||
+3
-1
@@ -4,7 +4,9 @@ import type z from "zod";
|
||||
import type { Workflow } from "@calcom/features/ee/workflows/lib/types";
|
||||
import type { AppsStatus, CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { Booking, NewBookingEventType, OriginalRescheduledBooking } from "../handleNewBooking/types";
|
||||
import type { Booking } from "../handleNewBooking/createBooking";
|
||||
import type { NewBookingEventType } from "../handleNewBooking/getEventTypesFromDB";
|
||||
import type { OriginalRescheduledBooking } from "../handleNewBooking/originalRescheduledBookingUtils";
|
||||
|
||||
export type BookingSeat = Prisma.BookingSeatGetPayload<{ include: { booking: true; attendee: true } }> | null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user