From 85425649d4dfa4334bc76eea6d7c06a7da8ed169 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 19 Mar 2024 14:41:16 +0000 Subject: [PATCH] fix: Crash of event types page if the upId is incorrect (#14136) --- .../routers/viewer/eventTypes/getByViewer.handler.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/trpc/server/routers/viewer/eventTypes/getByViewer.handler.ts b/packages/trpc/server/routers/viewer/eventTypes/getByViewer.handler.ts index a4f67422ac..b2f20c0b80 100644 --- a/packages/trpc/server/routers/viewer/eventTypes/getByViewer.handler.ts +++ b/packages/trpc/server/routers/viewer/eventTypes/getByViewer.handler.ts @@ -49,7 +49,13 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) => profile?.organization?.organizationSettings?.lockEventTypeCreationForUsers; const isFilterSet = input?.filters && hasFilter(input.filters); const isUpIdInFilter = input?.filters?.upIds?.includes(lightProfile.upId); - const shouldListUserEvents = !isFilterSet || isUpIdInFilter; + + let shouldListUserEvents = !isFilterSet || isUpIdInFilter; + // FIX: Handles the case when an upId != lightProfile - pretend like there is no filter. + // Results in {"eventTypeGroups":[],"profiles":[]} - this crashes all dependencies. + if (isFilterSet && input?.filters?.upIds && !isUpIdInFilter) { + shouldListUserEvents = true; + } const [profileMemberships, profileEventTypes] = await Promise.all([ MembershipRepository.findAllByUpIdIncludeTeamWithMembersAndEventTypes( { @@ -176,7 +182,7 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) => }) ); - if (!isFilterSet || isUpIdInFilter) { + if (shouldListUserEvents) { const bookerUrl = await getBookerBaseUrl(profile.organizationId ?? null); eventTypeGroups.push({ teamId: null,