fix: system user query shared product get mixed company

This commit is contained in:
Methapon2001 2024-12-19 16:13:12 +07:00
parent 6b4e13e94d
commit 58389ed47f
2 changed files with 29 additions and 22 deletions

View file

@ -33,11 +33,23 @@ export function createPermCondition(
globalAllow: (user: RequestWithUser["user"]) => boolean,
): (
user: RequestWithUser["user"],
opts?: { alwaysIncludeHead?: boolean; activeOnly?: boolean },
opts?: { alwaysIncludeHead?: boolean; activeOnly?: boolean; targetBranchId?: string },
) => Prisma.BranchWhereInput["OR"] {
return (user, opts) =>
isSystem(user)
? undefined
? opts?.targetBranchId
? [
{
id: opts.targetBranchId,
},
{
headOffice: { id: opts.targetBranchId },
},
{
branch: { some: { id: opts.targetBranchId } },
},
]
: undefined
: [
{
AND: opts?.activeOnly ? { status: { not: Status.INACTIVE } } : undefined,