* refactor: rename repository files to include Repository suffix - Rename attribute.ts -> attributeRepository.ts - Rename attributeOption.ts -> attributeOptionRepository.ts - Rename attributeToUser.ts -> attributeToUserRepository.ts - Update all import statements throughout codebase Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: rename repository files and classes with Prisma prefix - Rename attribute.ts -> PrismaAttributeRepository.ts - Rename attributeOption.ts -> PrismaAttributeOptionRepository.ts - Rename attributeToUser.ts -> PrismaAttributeToUserRepository.ts - Update class names to PrismaAttributeRepository, PrismaAttributeOptionRepository, PrismaAttributeToUserRepository - Update all import statements and references throughout codebase Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: update missed AttributeRepository import to PrismaAttributeRepository in teams members page Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import prisma from "@calcom/prisma";
|
|
|
|
export class PrismaAttributeRepository {
|
|
static async findManyByNamesAndOrgIdIncludeOptions({
|
|
attributeNames,
|
|
orgId,
|
|
}: {
|
|
attributeNames: string[];
|
|
orgId: number;
|
|
}) {
|
|
return prisma.attribute.findMany({
|
|
where: {
|
|
name: { in: attributeNames, mode: "insensitive" },
|
|
teamId: orgId,
|
|
},
|
|
include: {
|
|
options: {
|
|
select: {
|
|
id: true,
|
|
value: true,
|
|
slug: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findManyByOrgId({ orgId }: { orgId: number }) {
|
|
// It should be a faster query because of lesser number of attributes record and index on teamId
|
|
const result = await prisma.attribute.findMany({
|
|
where: {
|
|
teamId: orgId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
type: true,
|
|
slug: true,
|
|
options: true,
|
|
},
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
static async findAllByOrgIdWithOptions({ orgId }: { orgId: number }) {
|
|
return await prisma.attribute.findMany({
|
|
where: {
|
|
teamId: orgId,
|
|
},
|
|
include: {
|
|
options: true,
|
|
},
|
|
});
|
|
}
|
|
}
|