feat: v2 membership attributes (#21131)
* refactor: getByUserId.handler.ts * feat: return org membership attributes * docs * export new library function * test: attributes * chore: bump libraries * refactor: value -> option
This commit is contained in:
1 parent
ae2d85d81b
commit
dddbd7dad4
20 files changed
+4258
-136
No files matched your search
@@ -106,7 +106,8 @@ export { paymentDataSelect };
|
||||
export { getClientSecretFromPayment };
|
||||
|
||||
export { confirmHandler as confirmBookingHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler";
|
||||
|
||||
export { groupMembershipAttributes } from "@calcom/trpc/server/routers/viewer/attributes/getByUserId.handler";
|
||||
export type { GroupedAttribute } from "@calcom/trpc/server/routers/viewer/attributes/getByUserId.handler";
|
||||
export { getBookingFieldsWithSystemFields };
|
||||
|
||||
export { getRoutedUrl };
|
||||
|
||||
@@ -13,7 +13,7 @@ type GetOptions = {
|
||||
input: ZGetByUserIdSchema;
|
||||
};
|
||||
|
||||
type GroupedAttribute = {
|
||||
export type GroupedAttribute = {
|
||||
id: string;
|
||||
name: string;
|
||||
type: AttributeType;
|
||||
@@ -51,10 +51,15 @@ const getByUserIdHandler = async ({ input, ctx }: GetOptions) => {
|
||||
});
|
||||
}
|
||||
|
||||
const userAttributes = await prisma.attributeToUser.findMany({
|
||||
const userAttributes = await getMembershipAttributes(membership.id);
|
||||
return groupMembershipAttributes(userAttributes);
|
||||
};
|
||||
|
||||
async function getMembershipAttributes(membershipId: number) {
|
||||
return await prisma.attributeToUser.findMany({
|
||||
where: {
|
||||
member: {
|
||||
id: membership.id,
|
||||
id: membershipId,
|
||||
},
|
||||
attributeOption: {
|
||||
attribute: {
|
||||
@@ -81,8 +86,12 @@ const getByUserIdHandler = async ({ input, ctx }: GetOptions) => {
|
||||
weight: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const groupedAttributes = userAttributes.reduce<GroupedAttribute[]>((acc, assignment) => {
|
||||
type MembershipAttributes = Awaited<ReturnType<typeof getMembershipAttributes>>;
|
||||
|
||||
export function groupMembershipAttributes(membershipAttributes: MembershipAttributes): GroupedAttribute[] {
|
||||
return membershipAttributes.reduce<GroupedAttribute[]>((acc, assignment) => {
|
||||
const { attributeOption, createdByDSyncId, weight } = assignment;
|
||||
const { attribute: attrInfo, ...optionInfo } = attributeOption;
|
||||
const optionInfoWithCreatedByDSyncId = { ...optionInfo, createdByDSyncId, weight };
|
||||
@@ -105,8 +114,6 @@ const getByUserIdHandler = async ({ input, ctx }: GetOptions) => {
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return groupedAttributes;
|
||||
};
|
||||
}
|
||||
|
||||
export default getByUserIdHandler;
|
||||
Reference in new issue
Block a user