From fd454061e76d85d4c652b70dfa0c636738cc1b2d Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:05:14 +0000 Subject: [PATCH] fix profile circle dep (#19892) --- packages/lib/server/repository/profile.ts | 31 +++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/lib/server/repository/profile.ts b/packages/lib/server/repository/profile.ts index 8b1bd8e1af..cb384e9b92 100644 --- a/packages/lib/server/repository/profile.ts +++ b/packages/lib/server/repository/profile.ts @@ -6,11 +6,11 @@ import { safeStringify } from "@calcom/lib/safeStringify"; import prisma from "@calcom/prisma"; import { Prisma } from "@calcom/prisma/client"; import type { Team } from "@calcom/prisma/client"; +import { userMetadata } from "@calcom/prisma/zod-utils"; import type { UpId, UserAsPersonalProfile, UserProfile } from "@calcom/types/UserProfile"; import logger from "../../logger"; import { getParsedTeam } from "./teamUtils"; -import { UserRepository } from "./user"; const userSelect = Prisma.validator()({ name: true, @@ -66,6 +66,33 @@ export class ProfileRepository { return uuidv4(); } + // This is a minimal replication of UserRepository.findById only selecting the data we need here to prevent circular dependency + private static async findUserByid({ id }: { id: number }) { + const user = await prisma.user.findUnique({ + where: { + id, + }, + select: { + id: true, + username: true, + name: true, + avatarUrl: true, + startTime: true, + endTime: true, + bufferTime: true, + metadata: true, + }, + }); + + if (!user) { + return null; + } + return { + ...user, + metadata: userMetadata.parse(user.metadata), + }; + } + private static getInheritedDataFromUser({ user, }: { @@ -321,7 +348,7 @@ export class ProfileRepository { const lookupTarget = ProfileRepository.getLookupTarget(upId); log.debug("findByUpId", safeStringify({ upId, lookupTarget })); if (lookupTarget.type === LookupTarget.User) { - const user = await UserRepository.findById({ id: lookupTarget.id }); + const user = await this.findUserByid({ id: lookupTarget.id }); if (!user) { return null; }