|
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,
|
@@ -81,7 +79,6 @@ import { getPiiFreeCalendarEvent, getPiiFreeEventType, getPiiFreeUser } from "@c
|
81 | 79 | import { safeStringify } from "@calcom/lib/safeStringify";
|
82 | 80 | import { checkBookingLimits, checkDurationLimits, getLuckyUser } from "@calcom/lib/server";
|
83 | 81 | import { getTranslation } from "@calcom/lib/server/i18n";
|
84 |
| -import { UserRepository } from "@calcom/lib/server/repository/user"; |
85 | 82 | import { slugify } from "@calcom/lib/slugify";
|
86 | 83 | import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
|
87 | 84 | import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
@@ -110,6 +107,7 @@ import { checkForConflicts } from "./conflictChecker/checkForConflicts";
|
110 | 107 | import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials";
|
111 | 108 | import { refreshCredentials } from "./getAllCredentialsForUsersOnEvent/refreshCredentials";
|
112 | 109 | import getBookingDataSchema from "./getBookingDataSchema";
|
| 110 | +import { loadUsers } from "./handleNewBooking/loadUsers"; |
113 | 111 | import handleSeats from "./handleSeats/handleSeats";
|
114 | 112 | import type { BookingSeat } from "./handleSeats/types";
|
115 | 113 |
|
@@ -292,40 +290,6 @@ type IsFixedAwareUser = User & {
|
292 | 290 | priority?: number;
|
293 | 291 | };
|
294 | 292 |
|
295 |
| -const loadUsers = async (eventType: NewBookingEventType, dynamicUserList: string[], req: IncomingMessage) => { |
296 |
| - try { |
297 |
| - if (!eventType.id) { |
298 |
| - if (!Array.isArray(dynamicUserList) || dynamicUserList.length === 0) { |
299 |
| - throw new Error("dynamicUserList is not properly defined or empty."); |
300 |
| - } |
301 |
| - const { isValidOrgDomain, currentOrgDomain } = orgDomainConfig(req); |
302 |
| - const users = await findUsersByUsername({ |
303 |
| - usernameList: dynamicUserList, |
304 |
| - orgSlug: isValidOrgDomain ? currentOrgDomain : null, |
305 |
| - }); |
306 |
| - return users; |
307 |
| - } |
308 |
| - const hosts = eventType.hosts || []; |
309 |
| - |
310 |
| - if (!Array.isArray(hosts)) { |
311 |
| - throw new Error("eventType.hosts is not properly defined."); |
312 |
| - } |
313 |
| - |
314 |
| - const users = hosts.map(({ user, isFixed, priority }) => ({ |
315 |
| - ...user, |
316 |
| - isFixed, |
317 |
| - priority, |
318 |
| - })); |
319 |
| - |
320 |
| - return users.length ? users : eventType.users; |
321 |
| - } catch (error) { |
322 |
| - if (error instanceof HttpError || error instanceof Prisma.PrismaClientKnownRequestError) { |
323 |
| - throw new HttpError({ statusCode: 400, message: error.message }); |
324 |
| - } |
325 |
| - throw new HttpError({ statusCode: 500, message: "Unable to load users" }); |
326 |
| - } |
327 |
| -}; |
328 |
| - |
329 | 293 | export async function ensureAvailableUsers(
|
330 | 294 | eventType: Awaited<ReturnType<typeof getEventTypesFromDB>> & {
|
331 | 295 | users: IsFixedAwareUser[];
|
@@ -2650,40 +2614,3 @@ function handleCustomInputs(
|
2650 | 2614 | }
|
2651 | 2615 | });
|
2652 | 2616 | }
|
2653 |
| - |
2654 |
| -/** |
2655 |
| - * This method is mostly same as the one in UserRepository but it includes a lot more relations which are specific requirement here |
2656 |
| - * TODO: Figure out how to keep it in UserRepository and use it here |
2657 |
| - */ |
2658 |
| -export const findUsersByUsername = async ({ |
2659 |
| - usernameList, |
2660 |
| - orgSlug, |
2661 |
| -}: { |
2662 |
| - orgSlug: string | null; |
2663 |
| - usernameList: string[]; |
2664 |
| -}) => { |
2665 |
| - log.debug("findUsersByUsername", { usernameList, orgSlug }); |
2666 |
| - const { where, profiles } = await UserRepository._getWhereClauseForFindingUsersByUsername({ |
2667 |
| - orgSlug, |
2668 |
| - usernameList, |
2669 |
| - }); |
2670 |
| - return ( |
2671 |
| - await prisma.user.findMany({ |
2672 |
| - where, |
2673 |
| - select: { |
2674 |
| - ...userSelect.select, |
2675 |
| - credentials: { |
2676 |
| - select: credentialForCalendarServiceSelect, |
2677 |
| - }, |
2678 |
| - metadata: true, |
2679 |
| - }, |
2680 |
| - }) |
2681 |
| - ).map((user) => { |
2682 |
| - const profile = profiles?.find((profile) => profile.user.id === user.id) ?? null; |
2683 |
| - return { |
2684 |
| - ...user, |
2685 |
| - organizationId: profile?.organizationId ?? null, |
2686 |
| - profile, |
2687 |
| - }; |
2688 |
| - }); |
2689 |
| -}; |
0 commit comments