refactor: convert PrismaAttributeToUserRepository to accept Prisma as dependency (#26515)
* refactor: convert PrismaAttributeToUserRepository to accept Prisma as dependency Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: use Prisma types from generated client instead of custom types Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
joe@cal.com
Devin AI
parent
6fa525812c
commit
8b5d9202db
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user