Files
cal.diy/packages/trpc/server/routers/viewer/organizations/getFacetedValues.handler.ts
T
sean-brydonandKeith Williams 3c1297aa72 fix: calcom trpc sessio circle dep (#19893)
* fix trpc session circle dep

* fixes trpc session cirlce dep

* fix relative imports

* fix more imports to use types and not trpc

* fix exports

* Fixed types

---------

Co-authored-by: Keith Williams <[email protected]>
2025-03-19 05:50:22 -03:00

55 lines
1.2 KiB
TypeScript

import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../types";
type DeleteOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
};
export const getFacetedValuesHandler = async ({ ctx }: DeleteOptions) => {
const { user } = ctx;
const organizationId = user.organization?.id;
if (!organizationId) {
throw new TRPCError({ code: "NOT_FOUND", message: "Organization not found" });
}
const [teams, attributes] = await Promise.all([
prisma.team.findMany({
where: {
parentId: organizationId,
},
select: {
id: true,
name: true,
},
}),
prisma.attribute.findMany({
where: { teamId: organizationId },
select: {
id: true,
name: true,
options: {
select: {
value: true,
},
distinct: "value",
},
},
}),
]);
return {
teams: teams,
attributes: attributes,
roles: [MembershipRole.OWNER, MembershipRole.ADMIN, MembershipRole.MEMBER],
};
};
export default getFacetedValuesHandler;