chore: Upgrade prisma to 6.7.0 (#21264)
* chore: Upgrade prisma to 6.7.0 * Build fixes * type fixes Signed-off-by: Omar López <[email protected]> * Update schema.prisma * Patching * Revert "Update schema.prisma" This reverts commit 47d8618bf89ef4d007b30084df766f17281e21a1. * Revert "Patching" This reverts commit a1d2e3040e71690a44d4324db95d73b4d68c6adb. * Revert schema changes Signed-off-by: Omar López <[email protected]> * WIP Signed-off-by: Omar López <[email protected]> * Update getPublicEvent.ts * Update imports Signed-off-by: Omar López <[email protected]> * Update gitignore Signed-off-by: Omar López <[email protected]> * update remaining imports Signed-off-by: Omar López <[email protected]> * Delete .cursor/config.json * Discard changes to packages/features/eventtypes/lib/getPublicEvent.ts * Update _get.ts * Update user.ts * Update .gitignore * update * Update WorkflowStepContainer.tsx * Update next-auth-custom-adapter.ts * Update getPublicEvent.ts * Update workflow.ts * Update next-auth-custom-adapter.ts * Update next-auth-options.ts * Update bookingScenario.ts * fix missing imports * upgrades prismock Signed-off-by: Omar López <[email protected]> * patches prismock Signed-off-by: Omar López <[email protected]> * Update reschedule.test.ts * Update prisma.ts * patch prismock Signed-off-by: Omar López <[email protected]> * fix enums imports Signed-off-by: Omar López <[email protected]> * Revert "Update prisma.ts" This reverts commit 64edcf8db54171ff4456c209d563b5d431d99619. * Revert "patch prismock" This reverts commit e95819113dc9d88e7130947aa120cd42710977c8. * fix patch * Fix test that overrun the boundary, it shouldn't test too much * Move prisma import to changeSMSLockState * Bring back broken test without illegal imports * Merge with main and fix filter hosts by same round robin host * Fixed buildDryRunBooking fn tests * Fix and move ooo create or update handler test * Fix packages/features/eventtypes/lib/isCurrentlyAvailable.test.ts * Fix packages/trpc/server/routers/viewer/organizations/listMembers.handler.test.ts * Mock @calcom/prisma * Fix: verify-email.test.ts * fix: Moved WebhookService test and fixed default import mock * Fix: Added missing prisma mock, handleNewBooking uses that of course * We're not testing createContext here * fix: Prisma mock fix for listMembers.test.ts * More fixes to broken testcases * Forgot to remove borked test * Prevent the need to mock a lot of dependencies by moving out buildBaseWhereCondition to its own file * Temporarily skip getCalendarEvents, needs a rewrite * Fix: turns out you can access protected in testcases * fix further mocks * Added packages/features/insights/server/buildBaseWhereCondition.ts, types * Always great to have a mock and then not use it * And one less again. * fix: confirm.handler.test, didn't mock prisma * fix: Address minor nit by @eunjae & fix ImpersonationProvider test * Updated isPrismaAvailableCheck that doesn't crash on import * fix: Get Prisma directly from the client, it usually involves the Validator and does not need 'local' inclusion * Add zod-prisma-types without the generator enabled (commented out) * Uncomment and see what happens * Change method of import as imports did not work in Input Schemas * Remove custom 'zod' booking model, it does not belong with Prisma * Fix all other global Model imports * Rewrite most schema includes AND remove barrel file * Add bookingCreateBodySchema to features/bookings * Flurry of type fixes for compatibility with new zod gen * Refactor out the custom prisma type createEventTypeInput * Work around nullable eventTypeLocations * HandlePayment type fix * More fixes, final fix remaining is CompleteEventType * Should fix a bunch more booking related type errors * Missed one * Some props missing from BookingCreateBodySchema * Fix location type in handleChildrenEventTypes * Little bit hacky imo but it works * Final type error \o/ * Forgot to include Prisma * Do not include zod-utils in booker/types * Oops, was already including Booker/types * Fix membership type, also disallow updating createdAt/updatedAt, make part of patch/post * Fix api v1 type errors * Fix EventTypeDescription typings * Remove getParserWithGeneric, use userBodySchema with UserSchema * use centralized timeZoneSchema * Implement feedback by @zomars * Couple of WIP pushes * Fix tests * Type fixes in `handleChildrenEventTypes` test * Try and parse metadata before use * Change zod-prisma-types configuration for optimal performance * Fix prisma validator error in `prisma/selects/credential` * Disable seperate relations model, hits a bug * Import absolute - this makes rollup work in @platform/libraries * Attempt at removing resolutions override * Refactor using `Prisma.validator` to `satisfies` * Build atoms using @calcom/prisma/client * Build atoms using @calcom/prisma/client * fixes * Update eventTypeSelect.ts * Adjust `eventTypeMetaDataSchemaWithUntypedApps` from `unknown` to `record(any)` * `EventTypeDescription` rely on `descriptionAsSafeHTML` instead of `description` * Add `seatsPerTimeSlot` to event type public select * Fix typing in `users-public-view` getServerSide props * Add missing `schedulingType` to prop * chore: bump platform libraries * Function return type is illegal, not sure how this passed eslint (#21567) * Merged with main * Update updateTokenObject.ts * Update handleResponse.ts * Update index.ts * Update handleChildrenEventTypes.ts * Update booking-idempotency-key.ts * Update WebhookService.test.ts * Update events.test.ts * Update queued-response.test.ts * Update events.test.ts * Update getRoutedUrl.test.ts * fix: type checks Signed-off-by: Omar López <[email protected]> * fixes Signed-off-by: Omar López <[email protected]> * chore: bump platform libraries * Update yarn.lock * more fixes Signed-off-by: Omar López <[email protected]> * fixes Signed-off-by: Omar López <[email protected]> * biuld fixes * chore: bump platform libraries * Update conferencing.repository.ts * Update conferencing.repository.ts * Update getCalendarsEvents.test.ts * Update vite.config.js * chore: bump platform libraries * Update users.ts * Discard changes to docs/api-reference/v2/openapi.json * Update vite.config.ts * updated platform libraries * Update get.handler.test.ts * Update get.handler.test.ts * Update schema.prisma * Discard changes to docs/api-reference/v2/openapi.json * Update next-auth-custom-adapter.ts * Update team.ts * Flurry of type fixes * Fix majority of insight related type errors * Type fixes for unlink of account * Make user nullable again * Fixed a bunch of unit tests and one type error * Attempted mock fix * Attempted fix for Attribute type * Ensure default import becomes prisma, but not direct usage * Import default as prisma in prisma.module * Add attributeOption to attribute type * Fix calcom/prisma mock * Refactor Prisma client imports to @calcom/prisma/client Updated all imports from '@prisma/client' to '@calcom/prisma/client' across tests and repository files for consistency and to use the correct Prisma client package. This change improves maintainability and ensures the correct client is referenced throughout the codebase. * Undo removal of max-warnings=0 to get main to merge * Remove unit tests for e2e fixtures, provide new prisma mock * Mock @calcom/prisma in event manager * Mock @calcom/prisma in event manager * Add correct format even with --no-verify * Mock prisma in CalendarManager * Add mock for permission-check.service * Better injection in PrismaApiKeyRepository imports * More mock fixes :) * Fix listMembers.handler.test * Fix User import * Appropriately adjust all types to be imported as types, there were a lot of types imported as normal deps * Why was this a thing? * Strictly speaking; Not using prismock anymore * Ditched patch file for prismock * Fix output.service.ts platform type imports, need concrete for plainToClass * Better typing and tests for unlinkConnectedAccount.handler * Small type fix * Disable calendar cache tests as they are dependent on prismock * chore: bump platform lib * getRoutedUrl test remove of unused import * Extract select to external const on getEventTypesFromDB * Direct select of userSelect from selects/user * fix type error from merging 23653 * Fixed integration tests by removing hardcoded values that were possible due to mocking, but as its now directly hitting the db no longer * fix: vite config atoms prisma client type location * revert: example app prisma client * revert: example app prisma client * bump platform libs * fix: use class instead of type for DI of PlatformBookingsService * update platform libs * remove unused variable * chore: generate prisma client for api v2 * fix: api v2 e2e * fix: atoms e2e * fix: atoms e2e * fix: atoms e2e * fix: api v2 e2e * fix: tsconfig apiv2 enums * publish libraries * Simplify check for existence teamId --------- Signed-off-by: Omar López <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: supalarry <[email protected]> Co-authored-by: cal.com <[email protected]> Co-authored-by: Morgan <[email protected]> Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
623 files changed
+4363
-12559
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import type { EventType } from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { z } from "zod";
|
||||
@@ -10,6 +9,7 @@ import { TeamEventTypeForm } from "@calcom/features/ee/teams/components/TeamEven
|
||||
import { useCreateEventType } from "@calcom/lib/hooks/useCreateEventType";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
import type { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import { EventTypeDuplicateInput } from "@calcom/features/eventtypes/lib/types";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -13,7 +14,6 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import { md } from "@calcom/lib/markdownIt";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import turndown from "@calcom/lib/turndownService";
|
||||
import { EventTypeDuplicateInput } from "@calcom/prisma/zod/custom/eventtype";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { DialogContent, DialogFooter, DialogClose } from "@calcom/ui/components/dialog";
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { useMemo } from "react";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { Price } from "@calcom/features/bookings/components/event-meta/Price";
|
||||
import { PriceIcon } from "@calcom/features/bookings/components/event-meta/PriceIcon";
|
||||
@@ -9,16 +7,18 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
||||
import type { baseEventTypeSelect } from "@calcom/prisma";
|
||||
import type { Prisma, EventType } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/prisma/zod-utils";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Badge } from "@calcom/ui/components/badge";
|
||||
|
||||
export type EventTypeDescriptionProps = {
|
||||
eventType: Pick<
|
||||
z.infer<typeof EventTypeModel>,
|
||||
Exclude<keyof typeof baseEventTypeSelect, "recurringEvent"> | "metadata" | "seatsPerTimeSlot"
|
||||
EventType,
|
||||
| Exclude<keyof typeof baseEventTypeSelect, "recurringEvent" | "description">
|
||||
| "metadata"
|
||||
| "seatsPerTimeSlot"
|
||||
> & {
|
||||
descriptionAsSafeHTML?: string | null;
|
||||
recurringEvent: Prisma.JsonValue;
|
||||
@@ -41,15 +41,17 @@ export const EventTypeDescription = ({
|
||||
[eventType.recurringEvent]
|
||||
);
|
||||
|
||||
const metadata = eventTypeMetaDataSchemaWithTypedApps.parse(eventType.metadata);
|
||||
|
||||
const paymentAppData = getPaymentAppData({
|
||||
...eventType,
|
||||
metadata: eventTypeMetaDataSchemaWithTypedApps.parse(eventType.metadata),
|
||||
metadata,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={classNames("text-subtle", className)}>
|
||||
{eventType.description && (
|
||||
{eventType.descriptionAsSafeHTML && (
|
||||
<div
|
||||
className={classNames(
|
||||
"text-subtle line-clamp-3 break-words py-1 text-sm sm:max-w-[650px] [&_a]:text-blue-500 [&_a]:underline [&_a]:hover:text-blue-600",
|
||||
@@ -62,8 +64,8 @@ export const EventTypeDescription = ({
|
||||
/>
|
||||
)}
|
||||
<ul className="mt-2 flex flex-wrap gap-x-2 gap-y-1">
|
||||
{eventType.metadata?.multipleDuration ? (
|
||||
eventType.metadata.multipleDuration.map((dur, idx) => (
|
||||
{metadata?.multipleDuration ? (
|
||||
metadata.multipleDuration.map((dur, idx) => (
|
||||
<li key={idx}>
|
||||
<Badge variant="gray" startIcon="clock">
|
||||
{dur}m
|
||||
@@ -112,7 +114,7 @@ export const EventTypeDescription = ({
|
||||
{eventType.requiresConfirmation && (
|
||||
<li className="hidden xl:block" data-testid="requires-confirmation-badge">
|
||||
<Badge variant="gray" startIcon="clipboard">
|
||||
{eventType.metadata?.requiresConfirmationThreshold
|
||||
{metadata?.requiresConfirmationThreshold
|
||||
? t("may_require_confirmation")
|
||||
: t("requires_confirmation")}
|
||||
</Badge>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Webhook } from "@prisma/client";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useState } from "react";
|
||||
import { useFormContext, Controller } from "react-hook-form";
|
||||
@@ -14,6 +13,7 @@ import type { WebhookFormSubmitData } from "@calcom/features/webhooks/components
|
||||
import WebhookListItem from "@calcom/features/webhooks/components/WebhookListItem";
|
||||
import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { Webhook } from "@calcom/prisma/client";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Webhook } from "@prisma/client";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useFormContext } from "react-hook-form";
|
||||
@@ -13,6 +12,7 @@ import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberU
|
||||
import ServerTrans from "@calcom/lib/components/ServerTrans";
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { Webhook } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Alert } from "@calcom/ui/components/alert";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import type { User as UserType } from "@prisma/client";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import type { LocationObject } from "@calcom/app-store/locations";
|
||||
import { privacyFilteredLocations } from "@calcom/app-store/locations";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
@@ -16,6 +13,8 @@ import { isRecurringEvent, parseRecurringEvent } from "@calcom/lib/isRecurringEv
|
||||
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { User as UserType } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Team } from "@calcom/prisma/client";
|
||||
import type { BookerLayoutSettings } from "@calcom/prisma/zod-utils";
|
||||
import {
|
||||
@@ -574,301 +573,9 @@ export const getPublicEvent = async (
|
||||
};
|
||||
};
|
||||
|
||||
// A cleaner version of `getPublicEvent` that uses various helper functions like `processEventDataShared` and `getEventTypeHosts`
|
||||
// There is still a lot of room for improvement, but it's a good starting point.
|
||||
// For example, currently we have logic for all user / team / org / platform logic in this function.
|
||||
// We should break this down into more dedicated functions.
|
||||
const getPublicEventRefactored = async (
|
||||
username: string,
|
||||
eventSlug: string,
|
||||
isTeamEvent: boolean | undefined,
|
||||
org: string | null,
|
||||
prisma: PrismaClient,
|
||||
fromRedirectOfNonOrgLink: boolean,
|
||||
currentUserId?: number,
|
||||
fetchAllUsers = false
|
||||
) => {
|
||||
const usernameList = getUsernameList(username);
|
||||
const orgQuery = org ? getSlugOrRequestedSlug(org) : null;
|
||||
// In case of dynamic group event, we fetch user's data and use the default event.
|
||||
if (usernameList.length > 1) {
|
||||
const usersInOrgContext = await new UserRepository(prisma).findUsersByUsername({
|
||||
usernameList,
|
||||
orgSlug: org,
|
||||
});
|
||||
const users = usersInOrgContext;
|
||||
const eventData = getPublicEventSelect(true);
|
||||
|
||||
const defaultEvent = getDefaultEvent(eventSlug);
|
||||
let locations = defaultEvent.locations ? (defaultEvent.locations as LocationObject[]) : [];
|
||||
|
||||
// Get the preferred location type from the first user
|
||||
const firstUsersMetadata = userMetadataSchema.parse(users[0].metadata || {});
|
||||
const preferedLocationType = firstUsersMetadata?.defaultConferencingApp;
|
||||
|
||||
if (preferedLocationType?.appSlug) {
|
||||
const foundApp = getAppFromSlug(preferedLocationType.appSlug);
|
||||
const appType = foundApp?.appData?.location?.type;
|
||||
if (appType) {
|
||||
// Replace the location with the preferred location type
|
||||
// This will still be default to daily if the app is not found
|
||||
locations = [{ type: appType, link: preferedLocationType.appLink }] as LocationObject[];
|
||||
}
|
||||
}
|
||||
|
||||
const defaultEventBookerLayouts = {
|
||||
enabledLayouts: [...bookerLayoutOptions],
|
||||
defaultLayout: BookerLayouts.MONTH_VIEW,
|
||||
} as BookerLayoutSettings;
|
||||
const disableBookingTitle = !defaultEvent.isDynamic;
|
||||
const unPublishedOrgUser = users.find((user) => user.profile?.organization?.slug === null);
|
||||
|
||||
let orgDetails: Pick<Team, "logoUrl" | "name"> | undefined;
|
||||
if (org) {
|
||||
orgDetails = await prisma.team.findFirstOrThrow({
|
||||
where: {
|
||||
slug: org,
|
||||
},
|
||||
select: {
|
||||
logoUrl: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...defaultEvent,
|
||||
bookingFields: getBookingFieldsWithSystemFields({ ...defaultEvent, disableBookingTitle }),
|
||||
// Clears meta data since we don't want to send this in the public api.
|
||||
subsetOfUsers: users.map((user) => ({
|
||||
...user,
|
||||
metadata: undefined,
|
||||
bookerUrl: getBookerBaseUrlSync(user.profile?.organization?.slug ?? null),
|
||||
})),
|
||||
users: fetchAllUsers
|
||||
? users.map((user) => ({
|
||||
...user,
|
||||
metadata: undefined,
|
||||
bookerUrl: getBookerBaseUrlSync(user.profile?.organization?.slug ?? null),
|
||||
}))
|
||||
: undefined,
|
||||
locations: privacyFilteredLocations(locations),
|
||||
profile: {
|
||||
weekStart: users[0].weekStart,
|
||||
brandColor: users[0].brandColor,
|
||||
darkBrandColor: users[0].darkBrandColor,
|
||||
theme: null,
|
||||
bookerLayouts: bookerLayoutsSchema.parse(
|
||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||
),
|
||||
...(orgDetails
|
||||
? {
|
||||
image: getPlaceholderAvatar(orgDetails?.logoUrl, orgDetails?.name),
|
||||
name: orgDetails?.name,
|
||||
username: org,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
entity: {
|
||||
considerUnpublished: !fromRedirectOfNonOrgLink && unPublishedOrgUser !== undefined,
|
||||
fromRedirectOfNonOrgLink,
|
||||
orgSlug: org,
|
||||
name: unPublishedOrgUser?.profile?.organization?.name ?? null,
|
||||
teamSlug: null,
|
||||
logoUrl: null,
|
||||
hideProfileLink: false,
|
||||
},
|
||||
isInstantEvent: false,
|
||||
instantMeetingParameters: [],
|
||||
showInstantEventConnectNowModal: false,
|
||||
autoTranslateDescriptionEnabled: false,
|
||||
fieldTranslations: [],
|
||||
};
|
||||
}
|
||||
|
||||
const usersOrTeamQuery = isTeamEvent
|
||||
? {
|
||||
team: {
|
||||
...getSlugOrRequestedSlug(username),
|
||||
parent: orgQuery,
|
||||
},
|
||||
}
|
||||
: {
|
||||
users: {
|
||||
some: {
|
||||
...(orgQuery
|
||||
? {
|
||||
profiles: {
|
||||
some: {
|
||||
organization: orgQuery,
|
||||
username: username,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
username,
|
||||
profiles: { none: {} },
|
||||
}),
|
||||
},
|
||||
},
|
||||
team: null,
|
||||
};
|
||||
|
||||
// In case it's not a group event, it's either a single user or a team, and we query that data.
|
||||
let event = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
slug: eventSlug,
|
||||
...usersOrTeamQuery,
|
||||
},
|
||||
select: getPublicEventSelect(fetchAllUsers),
|
||||
});
|
||||
|
||||
// If no event was found, check for platform org user event
|
||||
if (!event && !orgQuery) {
|
||||
event = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
slug: eventSlug,
|
||||
users: {
|
||||
some: {
|
||||
username,
|
||||
isPlatformManaged: false,
|
||||
profiles: {
|
||||
some: {
|
||||
organization: {
|
||||
isPlatform: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: getPublicEventSelect(fetchAllUsers),
|
||||
});
|
||||
}
|
||||
|
||||
if (!event) return null;
|
||||
|
||||
const eventMetaData = eventTypeMetaDataSchemaWithTypedApps.parse(event.metadata || {});
|
||||
const teamMetadata = teamMetadataSchema.parse(event.team?.metadata || {});
|
||||
const { subsetOfHosts, hosts } = await getEventTypeHosts({
|
||||
hosts: event.hosts,
|
||||
fetchAllUsers,
|
||||
prisma,
|
||||
});
|
||||
|
||||
const eventWithUserProfiles = {
|
||||
...event,
|
||||
owner: event.owner
|
||||
? await new UserRepository(prisma).enrichUserWithItsProfile({
|
||||
user: event.owner,
|
||||
})
|
||||
: null,
|
||||
subsetOfHosts,
|
||||
hosts,
|
||||
};
|
||||
|
||||
let users =
|
||||
(await getUsersFromEvent(eventWithUserProfiles, prisma)) ||
|
||||
(await getOwnerFromUsersArray(prisma, event.id));
|
||||
|
||||
if (users === null) {
|
||||
throw new Error(`EventType ${event.id} has no owner or users.`);
|
||||
}
|
||||
//In case the event schedule is not defined ,use the event owner's default schedule
|
||||
if (!eventWithUserProfiles.schedule && eventWithUserProfiles.owner?.defaultScheduleId) {
|
||||
const eventOwnerDefaultSchedule = await prisma.schedule.findUnique({
|
||||
where: {
|
||||
id: eventWithUserProfiles.owner?.defaultScheduleId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
timeZone: true,
|
||||
},
|
||||
});
|
||||
eventWithUserProfiles.schedule = eventOwnerDefaultSchedule;
|
||||
}
|
||||
|
||||
let orgDetails: Pick<Team, "logoUrl" | "name"> | undefined | null;
|
||||
if (org) {
|
||||
orgDetails = await prisma.team.findFirst({
|
||||
where: {
|
||||
slug: org,
|
||||
parentId: null,
|
||||
},
|
||||
select: {
|
||||
logoUrl: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const isTeamAdminOrOwner = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: currentUserId ?? -1,
|
||||
teamId: event.teamId ?? -1,
|
||||
accepted: true,
|
||||
role: { in: ["ADMIN", "OWNER"] },
|
||||
},
|
||||
});
|
||||
|
||||
const isOrgAdminOrOwner = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: currentUserId ?? -1,
|
||||
teamId: event.team?.parentId ?? -1,
|
||||
accepted: true,
|
||||
role: { in: ["ADMIN", "OWNER"] },
|
||||
},
|
||||
});
|
||||
|
||||
if (event.team?.isPrivate && !isTeamAdminOrOwner && !isOrgAdminOrOwner) {
|
||||
users = [];
|
||||
}
|
||||
|
||||
const eventDataShared = await processEventDataShared({
|
||||
eventData: event,
|
||||
metadata: eventMetaData,
|
||||
prisma,
|
||||
});
|
||||
|
||||
return {
|
||||
...eventDataShared,
|
||||
// getPublicEvent-specific overrides
|
||||
owner: eventWithUserProfiles.owner,
|
||||
subsetOfHosts,
|
||||
hosts,
|
||||
// Sets user data on profile object for easier access
|
||||
profile: getProfileFromEvent(eventWithUserProfiles),
|
||||
subsetOfUsers: users,
|
||||
users: fetchAllUsers ? users : undefined,
|
||||
entity: {
|
||||
fromRedirectOfNonOrgLink,
|
||||
considerUnpublished:
|
||||
!fromRedirectOfNonOrgLink &&
|
||||
(eventWithUserProfiles.team?.slug === null ||
|
||||
eventWithUserProfiles.owner?.profile?.organization?.slug === null ||
|
||||
eventWithUserProfiles.team?.parent?.slug === null),
|
||||
orgSlug: org,
|
||||
teamSlug: (eventWithUserProfiles.team?.slug || teamMetadata?.requestedSlug) ?? null,
|
||||
name:
|
||||
(eventWithUserProfiles.owner?.profile?.organization?.name ||
|
||||
eventWithUserProfiles.team?.parent?.name ||
|
||||
eventWithUserProfiles.team?.name) ??
|
||||
null,
|
||||
hideProfileLink: eventWithUserProfiles.team?.hideTeamProfileLink ?? false,
|
||||
...(orgDetails
|
||||
? {
|
||||
logoUrl: getPlaceholderAvatar(orgDetails?.logoUrl, orgDetails?.name),
|
||||
name: orgDetails?.name,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const eventData = {
|
||||
select: getPublicEventSelect(true),
|
||||
} satisfies Prisma.EventTypeArgs;
|
||||
|
||||
type Event = Prisma.EventTypeGetPayload<typeof eventData>;
|
||||
type Event = Prisma.EventTypeGetPayload<{ select: typeof eventData }>;
|
||||
|
||||
type GetProfileFromEventInput = Omit<Event, "hosts"> & {
|
||||
hosts?: Event["hosts"];
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { describe, it, expect, vi, beforeAll } from "vitest";
|
||||
|
||||
import { isCurrentlyAvailable } from "./getPublicEvent";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const prismaMock = {
|
||||
schedule: {
|
||||
findUniqueOrThrow: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
vi.mock("@calcom/prisma", () => {
|
||||
return {
|
||||
PrismaClient: vi.fn(() => prismaMock),
|
||||
};
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
vi.setSystemTime(new Date("2024-09-01T10:00:00Z"));
|
||||
@@ -19,12 +28,12 @@ describe("isCurrentlyAvailable", () => {
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(prisma.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
vi.spyOn(prismaMock.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
availability: mockAvailability,
|
||||
});
|
||||
|
||||
const result = await isCurrentlyAvailable({
|
||||
prisma,
|
||||
prisma: prismaMock,
|
||||
instantMeetingScheduleId: 1,
|
||||
availabilityTimezone: "Europe/London",
|
||||
length: 30,
|
||||
@@ -42,12 +51,12 @@ describe("isCurrentlyAvailable", () => {
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(prisma.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
vi.spyOn(prismaMock.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
availability: mockAvailability,
|
||||
});
|
||||
|
||||
const result = await isCurrentlyAvailable({
|
||||
prisma,
|
||||
prisma: prismaMock,
|
||||
instantMeetingScheduleId: 1,
|
||||
availabilityTimezone: "Europe/London",
|
||||
length: 30,
|
||||
@@ -65,12 +74,12 @@ describe("isCurrentlyAvailable", () => {
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(prisma.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
vi.spyOn(prismaMock.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
availability: mockAvailability,
|
||||
});
|
||||
|
||||
const result = await isCurrentlyAvailable({
|
||||
prisma,
|
||||
prisma: prismaMock,
|
||||
instantMeetingScheduleId: 1,
|
||||
availabilityTimezone: "Europe/London",
|
||||
length: 30,
|
||||
@@ -88,12 +97,12 @@ describe("isCurrentlyAvailable", () => {
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(prisma.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
vi.spyOn(prismaMock.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
availability: mockAvailability,
|
||||
});
|
||||
|
||||
const result = await isCurrentlyAvailable({
|
||||
prisma,
|
||||
prisma: prismaMock,
|
||||
instantMeetingScheduleId: 1,
|
||||
availabilityTimezone: "Europe/London",
|
||||
length: 60,
|
||||
@@ -118,12 +127,12 @@ describe("isCurrentlyAvailable", () => {
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(prisma.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
vi.spyOn(prismaMock.schedule, "findUniqueOrThrow").mockResolvedValue({
|
||||
availability: mockAvailability,
|
||||
});
|
||||
|
||||
const result = await isCurrentlyAvailable({
|
||||
prisma,
|
||||
prisma: prismaMock,
|
||||
instantMeetingScheduleId: 1,
|
||||
availabilityTimezone: "Europe/London",
|
||||
length: 30,
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import type { z } from "zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import type { ChildrenEventType } from "@calcom/features/eventtypes/components/ChildrenEventTypeSelect";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import type { EventLocationType } from "@calcom/lib/location";
|
||||
import type { AttributesQueryValue } from "@calcom/lib/raqb/types";
|
||||
import type { EventTypeTranslation } from "@calcom/prisma/client";
|
||||
import type { PeriodType, SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { BookerLayoutSettings, eventTypeMetaDataSchemaWithTypedApps } from "@calcom/prisma/zod-utils";
|
||||
import type { customInputSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||
import type { eventTypeColor } from "@calcom/prisma/zod-utils";
|
||||
import type { PeriodType } from "@calcom/prisma/enums";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type {
|
||||
BookerLayoutSettings,
|
||||
customInputSchema,
|
||||
eventTypeMetaDataSchemaWithTypedApps,
|
||||
eventTypeBookingFields,
|
||||
eventTypeColor,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import { eventTypeSlug, eventTypeLocations, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { RouterOutputs, RouterInputs } from "@calcom/trpc/react";
|
||||
import type { RecurringEvent } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -228,6 +233,55 @@ export type SelectClassNames = {
|
||||
container?: string;
|
||||
};
|
||||
|
||||
export const EventTypeDuplicateInput = z
|
||||
.object({
|
||||
id: z.number(),
|
||||
slug: z.string(),
|
||||
title: z.string().min(1),
|
||||
description: z.string(),
|
||||
length: z.number(),
|
||||
teamId: z.number().nullish(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const calVideoSettingsSchema = z
|
||||
.object({
|
||||
disableRecordingForGuests: z.boolean().nullish(),
|
||||
disableRecordingForOrganizer: z.boolean().nullish(),
|
||||
enableAutomaticTranscription: z.boolean().nullish(),
|
||||
enableAutomaticRecordingForOrganizer: z.boolean().nullish(),
|
||||
disableTranscriptionForGuests: z.boolean().nullish(),
|
||||
disableTranscriptionForOrganizer: z.boolean().nullish(),
|
||||
redirectUrlOnExit: z.string().url().nullish(),
|
||||
})
|
||||
.optional()
|
||||
.nullable();
|
||||
|
||||
export const createEventTypeInput = z
|
||||
.object({
|
||||
title: z.string().min(1),
|
||||
slug: eventTypeSlug,
|
||||
description: z.string().nullish(),
|
||||
length: z.number().int(),
|
||||
hidden: z.boolean(),
|
||||
teamId: z.number().int().nullish(),
|
||||
schedulingType: z.nativeEnum(SchedulingType).nullish(),
|
||||
locations: eventTypeLocations,
|
||||
metadata: EventTypeMetaDataSchema.optional(),
|
||||
disableGuests: z.boolean().optional(),
|
||||
slotInterval: z.number().min(0).nullish(),
|
||||
minimumBookingNotice: z.number().int().min(0).optional(),
|
||||
beforeEventBuffer: z.number().int().min(0).optional(),
|
||||
afterEventBuffer: z.number().int().min(0).optional(),
|
||||
scheduleId: z.number().int().optional(),
|
||||
calVideoSettings: calVideoSettingsSchema,
|
||||
})
|
||||
.partial({ hidden: true, locations: true })
|
||||
.refine((data) => (data.teamId ? data.teamId && data.schedulingType : true), {
|
||||
path: ["schedulingType"],
|
||||
message: "You must select a scheduling type for team events",
|
||||
});
|
||||
|
||||
export type FormValidationResult = {
|
||||
isValid: boolean;
|
||||
errors: Record<string, unknown>;
|
||||
|
||||
Reference in new issue
Block a user