refactor: add helper function
This commit is contained in:
parent
114f008934
commit
f79650a9bd
1 changed files with 22 additions and 0 deletions
|
|
@ -16,6 +16,28 @@ export function branchRelationPermInclude(user: RequestWithUser["user"]) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createPermCondition(globalAllow: (user: RequestWithUser["user"]) => boolean) {
|
||||||
|
return (user: RequestWithUser["user"]) =>
|
||||||
|
isSystem(user)
|
||||||
|
? undefined
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
user: { some: { userId: user.sub } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
branch: { some: { user: { some: { userId: user.sub } } } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headOffice: globalAllow(user)
|
||||||
|
? { branch: { some: { user: { some: { userId: user.sub } } } } }
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headOffice: globalAllow(user) ? { user: { some: { userId: user.sub } } } : undefined,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
export async function getBranchPermissionCheck(user: RequestWithUser["user"], branchId: string) {
|
export async function getBranchPermissionCheck(user: RequestWithUser["user"], branchId: string) {
|
||||||
return await prisma.branch.findUnique({
|
return await prisma.branch.findUnique({
|
||||||
include: {
|
include: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue