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:
Lauris Skraucis authored and GitHub committed 2025-05-08 23:37:24 +01:00
1 parent ae2d85d81b
commit dddbd7dad4
20 files changed
+4258 -136

No files matched your search

@@ -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;