diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts index b18d36d945a413..4baa35c80d964d 100644 --- a/packages/core/getUserAvailability.ts +++ b/packages/core/getUserAvailability.ts @@ -157,6 +157,45 @@ const _getUser = async (where: Prisma.UserWhereInput) => { type GetUser = Awaited>; +export type GetUserAvailabilityInitialData = { + user?: GetUser; + eventType?: EventType; + currentSeats?: CurrentSeats; + rescheduleUid?: string | null; + currentBookings?: (Pick & { + eventType: Pick< + PrismaEventType, + "id" | "beforeEventBuffer" | "afterEventBuffer" | "seatsPerTimeSlot" + > | null; + _count?: { + seatsReferences: number; + }; + })[]; + outOfOfficeDays?: (Pick & { + user: Pick; + toUser: Pick | null; + reason: Pick | null; + })[]; + busyTimesFromLimitsBookings: EventBusyDetails[]; +}; + +export type GetAvailabilityUser = NonNullable; + +type GetUserAvailabilityQuery = { + withSource?: boolean; + username?: string; + userId?: number; + dateFrom: string; + dateTo: string; + eventTypeId?: number; + afterEventBuffer?: number; + beforeEventBuffer?: number; + duration?: number; + returnDateOverrides: boolean; + bypassBusyCalendarTimes: boolean; + shouldServeCache?: boolean; +}; + export const getCurrentSeats = async ( ...args: Parameters ): Promise> => { @@ -222,47 +261,16 @@ export type CurrentSeats = Awaited>; export const getUserAvailability = async ( ...args: Parameters -): Promise> => { +): Promise => { return monitorCallbackAsync(_getUserAvailability, ...args); }; +type GetUserAvailabilityResult = ReturnType; + /** This should be called getUsersWorkingHoursAndBusySlots (...and remaining seats, and final timezone) */ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseAndEverythingElse( - query: { - withSource?: boolean; - username?: string; - userId?: number; - dateFrom: string; - dateTo: string; - eventTypeId?: number; - afterEventBuffer?: number; - beforeEventBuffer?: number; - duration?: number; - returnDateOverrides: boolean; - bypassBusyCalendarTimes: boolean; - shouldServeCache?: boolean; - }, - initialData?: { - user?: GetUser; - eventType?: EventType; - currentSeats?: CurrentSeats; - rescheduleUid?: string | null; - currentBookings?: (Pick & { - eventType: Pick< - PrismaEventType, - "id" | "beforeEventBuffer" | "afterEventBuffer" | "seatsPerTimeSlot" - > | null; - _count?: { - seatsReferences: number; - }; - })[]; - outOfOfficeDays?: (Pick & { - user: Pick; - toUser: Pick | null; - reason: Pick | null; - })[]; - busyTimesFromLimitsBookings: EventBusyDetails[]; - } + query: GetUserAvailabilityQuery, + initialData?: GetUserAvailabilityInitialData ) { const { username, @@ -656,22 +664,16 @@ const calculateOutOfOfficeRanges = ( }, {}); }; -type GetUserAvailabilityQuery = Parameters[0]; -type GetUserAvailabilityInitialData = NonNullable[1]>; -export type GetAvailabilityUser = NonNullable; - -const _getUsersAvailability = async ({ - users, - query, - initialData, -}: { +type GetUsersAvailabilityProps = { users: (GetAvailabilityUser & { currentBookings?: GetUserAvailabilityInitialData["currentBookings"]; outOfOfficeDays?: GetUserAvailabilityInitialData["outOfOfficeDays"]; })[]; query: Omit; initialData?: Omit; -}) => { +}; + +const _getUsersAvailability = async ({ users, query, initialData }: GetUsersAvailabilityProps) => { return await Promise.all( users.map((user) => _getUserAvailability( @@ -695,6 +697,6 @@ const _getUsersAvailability = async ({ export const getUsersAvailability = async ( ...args: Parameters -): Promise> => { +): Promise[]> => { return monitorCallbackAsync(_getUsersAvailability, ...args); };