From 150dc3acb9ded0a071dab1dcc51bc41fec43bf4f Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 10 Oct 2023 18:08:06 +0100 Subject: [PATCH] fix: Remove credentials and some ts fixes (#11794) --- packages/app-store/server.ts | 16 ++++++++-------- packages/lib/getEventTypeById.ts | 23 +---------------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/packages/app-store/server.ts b/packages/app-store/server.ts index 0ff0c47e00..f88ec7597f 100644 --- a/packages/app-store/server.ts +++ b/packages/app-store/server.ts @@ -1,6 +1,6 @@ +import type { Prisma } from "@prisma/client"; import type { TFunction } from "next-i18next"; -import type { CredentialDataWithTeamName } from "@calcom/app-store/utils"; import { defaultVideoAppCategories } from "@calcom/app-store/utils"; import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials"; import { prisma } from "@calcom/prisma"; @@ -21,11 +21,11 @@ export async function getLocationGroupedOptions( disabled?: boolean; icon?: string; slug?: string; - credential?: CredentialDataWithTeamName; }[] > = {}; - let idToSearchObject = {}; + // don't default to {}, when you do TS no longer determines the right types. + let idToSearchObject: Prisma.CredentialWhereInput; if ("teamId" in userOrTeamId) { const teamId = userOrTeamId.teamId; @@ -84,11 +84,11 @@ export async function getLocationGroupedOptions( : app.categories[0] || app.category; if (!groupByCategory) groupByCategory = AppCategories.conferencing; - for (const credential of app.credentials) { - const label = `${app.locationOption.label} ${ - credential.team?.name ? `(${credential.team.name})` : "" - }`; - const option = { ...app.locationOption, label, icon: app.logo, slug: app.slug, credential }; + for (const { teamName } of app.credentials.map((credential) => ({ + teamName: credential.team?.name, + }))) { + const label = `${app.locationOption.label} ${teamName ? `(${teamName})` : ""}`; + const option = { ...app.locationOption, label, icon: app.logo, slug: app.slug }; if (apps[groupByCategory]) { apps[groupByCategory] = [...apps[groupByCategory], option]; } else { diff --git a/packages/lib/getEventTypeById.ts b/packages/lib/getEventTypeById.ts index 5d4eafed6f..3f96aa9e36 100644 --- a/packages/lib/getEventTypeById.ts +++ b/packages/lib/getEventTypeById.ts @@ -11,7 +11,7 @@ import { CAL_URL } from "@calcom/lib/constants"; import { getTranslation } from "@calcom/lib/server/i18n"; import type { PrismaClient } from "@calcom/prisma"; import type { Credential } from "@calcom/prisma/client"; -import { SchedulingType, MembershipRole, AppCategories } from "@calcom/prisma/enums"; +import { SchedulingType, MembershipRole } from "@calcom/prisma/enums"; import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; import { TRPCError } from "@trpc/server"; @@ -230,27 +230,6 @@ export default async function getEventTypeById({ } } - const credentials = await prisma.credential.findMany({ - where: { - userId, - app: { - enabled: true, - categories: { - hasSome: [AppCategories.conferencing, AppCategories.video, AppCategories.payment], - }, - }, - }, - select: { - id: true, - type: true, - key: true, - userId: true, - teamId: true, - appId: true, - invalid: true, - }, - }); - const { locations, metadata, ...restEventType } = rawEventType; const newMetadata = EventTypeMetaDataSchema.parse(metadata || {}) || {}; const apps = newMetadata?.apps || {};