feat(customers): add optional group assignees with OR visibility for people, companies, and birthdays

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-12 12:59:49 +03:30
co-authored by Cursor
parent 453ff1a5f6
commit b583858088
17 changed files with 847 additions and 53 deletions
+20
View File
@@ -135,6 +135,23 @@ function orParts<T>(parts: T[]): T | { OR: T[] } | { id: string } {
return parts.length === 1 ? parts[0]! : { OR: parts };
}
/** اعضای گروه‌هایی که کاربر مسئولشان است */
function personViaGroupAssignee(userId: string): Prisma.PersonWhereInput {
return {
groupLinks: {
some: { group: { assignees: { some: { id: userId } } } },
},
};
}
function companyViaGroupAssignee(userId: string): Prisma.CompanyWhereInput {
return {
groupLinks: {
some: { group: { assignees: { some: { id: userId } } } },
},
};
}
export function customersPersonWhere(
actor: Pick<Actor, 'userId' | 'role' | 'customersAccess' | 'teamPeerIds'>,
): Prisma.PersonWhereInput {
@@ -149,6 +166,8 @@ export function customersPersonWhere(
});
if (w) parts.push(w);
}
// مسئول گروه: اتحاد با محدودیت نقش (مالک خودم یا عضو گروه تحت مسئولیت)
parts.push(personViaGroupAssignee(actor.userId));
return orParts(parts);
}
@@ -188,6 +207,7 @@ export function customersCompanyWhere(
if (!and.length) continue;
parts.push(and.length === 1 ? and[0]! : { AND: and });
}
parts.push(companyViaGroupAssignee(actor.userId));
return orParts(parts);
}