Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: convert PrismaAttributeToUserRepository to accept Prisma as dependency (#26515)

Joe Au-Yeung8b5d9202db71
diff --git a/packages/features/attributes/lib/getAttributes.ts b/packages/features/attributes/lib/getAttributes.ts
index 34a2a1394aa..0e6ebbf75e2 100644
--- a/packages/features/attributes/lib/getAttributes.ts
+++ b/packages/features/attributes/lib/getAttributes.ts
@@ -221,6 +221,7 @@ async function _getOrgMembershipToUserIdForTeam({ orgId, teamId }: { orgId: numb
async function _queryAllData({ orgId, teamId }: { orgId: number; teamId: number }) {
const attributeRepo = new PrismaAttributeRepository(prisma);
+ const attributeToUserRepo = new PrismaAttributeToUserRepository(prisma);
const [orgMembershipToUserIdForTeamMembers, attributesOfTheOrg] = await Promise.all([
_getOrgMembershipToUserIdForTeam({ orgId, teamId }),
@@ -230,7 +231,7 @@ async function _queryAllData({ orgId, teamId }: { orgId: number; teamId: number
const orgMembershipIds = Array.from(orgMembershipToUserIdForTeamMembers.keys());
// Get all the attributes assigned to the members of the team
- const attributesToUsersForTeam = await PrismaAttributeToUserRepository.findManyByOrgMembershipIds({
+ const attributesToUsersForTeam = await attributeToUserRepo.findManyByOrgMembershipIds({
orgMembershipIds,
});
diff --git a/packages/features/attributes/lib/utils.ts b/packages/features/attributes/lib/utils.ts
index 11699701e38..aaa8839cc75 100644
--- a/packages/features/attributes/lib/utils.ts
+++ b/packages/features/attributes/lib/utils.ts
@@ -1,4 +1,5 @@
import { PrismaAttributeToUserRepository } from "@calcom/features/attributes/repositories/PrismaAttributeToUserRepository";
+import prisma from "@calcom/prisma";
export const getWhereClauseForAttributeOptionsManagedByCalcom = () => {
// Neither created nor updated by DSync
@@ -10,7 +11,8 @@ export const getWhereClauseForAttributeOptionsManagedByCalcom = () => {
};
export const findAssignmentsForMember = async ({ memberId }: { memberId: number }) => {
- const assignments = await PrismaAttributeToUserRepository.findManyIncludeAttribute({ memberId });
+ const attributeToUserRepo = new PrismaAttributeToUserRepository(prisma);
+ const assignments = await attributeToUserRepo.findManyIncludeAttribute({ memberId });
return assignments.map((assignment) => ({
...assignment,
attributeOption: {
diff --git a/packages/features/attributes/repositories/PrismaAttributeToUserRepository.ts b/packages/features/attributes/repositories/PrismaAttributeToUserRepository.ts
index d798a86d390..193822d39e3 100644
--- a/packages/features/attributes/repositories/PrismaAttributeToUserRepository.ts
+++ b/packages/features/attributes/repositories/PrismaAttributeToUserRepository.ts
@@ -1,20 +1,22 @@
-import { prisma } from "@calcom/prisma";
-import type { Prisma } from "@calcom/prisma/client";
+import type { PrismaClient } from "@calcom/prisma";
+import type { Prisma } from "@calcom/prisma/generated/prisma/client";
export class PrismaAttributeToUserRepository {
- static async createManySkipDuplicates(data: Prisma.AttributeToUserCreateManyInput[]) {
- return await prisma.attributeToUser.createMany({ data, skipDuplicates: true });
+ constructor(private prismaClient: PrismaClient) {}
+
+ async createManySkipDuplicates(data: Prisma.AttributeToUserCreateManyInput[]) {
+ return await this.prismaClient.attributeToUser.createMany({ data, skipDuplicates: true });
}
- static async deleteMany(where: Prisma.AttributeToUserWhereInput) {
+ async deleteMany(where: Prisma.AttributeToUserWhereInput) {
if (Object.keys(where).length === 0) {
throw new Error("Empty where clause provided to deleteMany. Potential data loss risk.");
}
- return await prisma.attributeToUser.deleteMany({ where });
+ return await this.prismaClient.attributeToUser.deleteMany({ where });
}
- static async findManyIncludeAttribute(where: Prisma.AttributeToUserWhereInput) {
- return await prisma.attributeToUser.findMany({
+ async findManyIncludeAttribute(where: Prisma.AttributeToUserWhereInput) {
+ return await this.prismaClient.attributeToUser.findMany({
where,
include: {
attributeOption: {
@@ -28,12 +30,12 @@ export class PrismaAttributeToUserRepository {
});
}
- static async findManyByOrgMembershipIds({ orgMembershipIds }: { orgMembershipIds: number[] }) {
+ async findManyByOrgMembershipIds({ orgMembershipIds }: { orgMembershipIds: number[] }) {
if (!orgMembershipIds.length) {
return [];
}
- const attributesAssignedToTeamMembers = await prisma.attributeToUser.findMany({
+ const attributesAssignedToTeamMembers = await this.prismaClient.attributeToUser.findMany({
where: {
memberId: {
in: orgMembershipIds,