|
1 | 1 | import type { App, DestinationCalendar, EventTypeCustomInput } from "@prisma/client";
|
2 | 2 | import { Prisma } from "@prisma/client";
|
3 |
| -import type { IncomingMessage } from "http"; |
4 | 3 | import { isValidPhoneNumber } from "libphonenumber-js";
|
5 | 4 | // eslint-disable-next-line no-restricted-imports
|
6 | 5 | import { cloneDeep } from "lodash";
|
@@ -41,7 +40,6 @@ import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/
|
41 | 40 | import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
42 | 41 | import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
43 | 42 | import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
44 |
| -import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains"; |
45 | 43 | import {
|
46 | 44 | allowDisablingAttendeeConfirmationEmails,
|
47 | 45 | allowDisablingHostConfirmationEmails,
|
@@ -79,7 +77,6 @@ import { getPiiFreeCalendarEvent, getPiiFreeEventType, getPiiFreeUser } from "@c
|
79 | 77 | import { safeStringify } from "@calcom/lib/safeStringify";
|
80 | 78 | import { checkBookingLimits, checkDurationLimits, getLuckyUser } from "@calcom/lib/server";
|
81 | 79 | import { getTranslation } from "@calcom/lib/server/i18n";
|
82 |
| -import { UserRepository } from "@calcom/lib/server/repository/user"; |
83 | 80 | import { slugify } from "@calcom/lib/slugify";
|
84 | 81 | import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
|
85 | 82 | import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
@@ -112,6 +109,7 @@ import { checkForConflicts } from "./conflictChecker/checkForConflicts";
|
112 | 109 | import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials";
|
113 | 110 | import { refreshCredentials } from "./getAllCredentialsForUsersOnEvent/refreshCredentials";
|
114 | 111 | import getBookingDataSchema from "./getBookingDataSchema";
|
| 112 | +import { loadUsers } from "./handleNewBooking/loadUsers"; |
115 | 113 | import handleSeats from "./handleSeats/handleSeats";
|
116 | 114 | import type { BookingSeat } from "./handleSeats/types";
|
117 | 115 |
|
@@ -297,40 +295,6 @@ type IsFixedAwareUser = User & {
|
297 | 295 | priority?: number;
|
298 | 296 | };
|
299 | 297 |
|
300 |
| -const loadUsers = async (eventType: NewBookingEventType, dynamicUserList: string[], req: IncomingMessage) => { |
301 |
| - try { |
302 |
| - if (!eventType.id) { |
303 |
| - if (!Array.isArray(dynamicUserList) || dynamicUserList.length === 0) { |
304 |
| - throw new Error("dynamicUserList is not properly defined or empty."); |
305 |
| - } |
306 |
| - const { isValidOrgDomain, currentOrgDomain } = orgDomainConfig(req); |
307 |
| - const users = await findUsersByUsername({ |
308 |
| - usernameList: dynamicUserList, |
309 |
| - orgSlug: isValidOrgDomain ? currentOrgDomain : null, |
310 |
| - }); |
311 |
| - return users; |
312 |
| - } |
313 |
| - const hosts = eventType.hosts || []; |
314 |
| - |
315 |
| - if (!Array.isArray(hosts)) { |
316 |
| - throw new Error("eventType.hosts is not properly defined."); |
317 |
| - } |
318 |
| - |
319 |
| - const users = hosts.map(({ user, isFixed, priority }) => ({ |
320 |
| - ...user, |
321 |
| - isFixed, |
322 |
| - priority, |
323 |
| - })); |
324 |
| - |
325 |
| - return users.length ? users : eventType.users; |
326 |
| - } catch (error) { |
327 |
| - if (error instanceof HttpError || error instanceof Prisma.PrismaClientKnownRequestError) { |
328 |
| - throw new HttpError({ statusCode: 400, message: error.message }); |
329 |
| - } |
330 |
| - throw new HttpError({ statusCode: 500, message: "Unable to load users" }); |
331 |
| - } |
332 |
| -}; |
333 |
| - |
334 | 298 | export async function ensureAvailableUsers(
|
335 | 299 | eventType: Awaited<ReturnType<typeof getEventTypesFromDB>> & {
|
336 | 300 | users: IsFixedAwareUser[];
|
@@ -2647,40 +2611,3 @@ function handleCustomInputs(
|
2647 | 2611 | }
|
2648 | 2612 | });
|
2649 | 2613 | }
|
2650 |
| - |
2651 |
| -/** |
2652 |
| - * This method is mostly same as the one in UserRepository but it includes a lot more relations which are specific requirement here |
2653 |
| - * TODO: Figure out how to keep it in UserRepository and use it here |
2654 |
| - */ |
2655 |
| -export const findUsersByUsername = async ({ |
2656 |
| - usernameList, |
2657 |
| - orgSlug, |
2658 |
| -}: { |
2659 |
| - orgSlug: string | null; |
2660 |
| - usernameList: string[]; |
2661 |
| -}) => { |
2662 |
| - log.debug("findUsersByUsername", { usernameList, orgSlug }); |
2663 |
| - const { where, profiles } = await UserRepository._getWhereClauseForFindingUsersByUsername({ |
2664 |
| - orgSlug, |
2665 |
| - usernameList, |
2666 |
| - }); |
2667 |
| - return ( |
2668 |
| - await prisma.user.findMany({ |
2669 |
| - where, |
2670 |
| - select: { |
2671 |
| - ...userSelect.select, |
2672 |
| - credentials: { |
2673 |
| - select: credentialForCalendarServiceSelect, |
2674 |
| - }, |
2675 |
| - metadata: true, |
2676 |
| - }, |
2677 |
| - }) |
2678 |
| - ).map((user) => { |
2679 |
| - const profile = profiles?.find((profile) => profile.user.id === user.id) ?? null; |
2680 |
| - return { |
2681 |
| - ...user, |
2682 |
| - organizationId: profile?.organizationId ?? null, |
2683 |
| - profile, |
2684 |
| - }; |
2685 |
| - }); |
2686 |
| -}; |
0 commit comments