Skip to content

Scheduling infrastructure for absolutely everyone.

fix profile circle dep (#19892)

sean-brydonfd454061e76d
diff --git a/packages/lib/server/repository/profile.ts b/packages/lib/server/repository/profile.ts
index 8b1bd8e1af4..cb384e9b923 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<Prisma.UserSelect>()({
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;
}