feat: shared between company

This commit is contained in:
Methapon Metanipat 2024-09-10 17:00:21 +07:00
parent 2fff5f7e47
commit 2c8faef25c
3 changed files with 67 additions and 14 deletions

View file

@ -42,6 +42,7 @@ function globalAllow(user: RequestWithUser["user"]) {
return allowList.some((v) => user.roles?.includes(v));
}
const permissionCondShared = createPermCondition((_) => true);
const permissionCond = createPermCondition(globalAllow);
const permissionCheck = createPermCheck(globalAllow);
@ -89,13 +90,21 @@ export class ServiceController extends Controller {
return await prisma.service.count({
where: {
productGroupId,
productGroup: isSystem(req.user)
OR: isSystem(req.user)
? undefined
: {
registeredBranch: {
OR: permissionCond(req.user),
: [
{
productGroup: {
registeredBranch: { OR: permissionCond(req.user) },
},
},
},
{
shared: true,
productGroup: {
registeredBranch: { OR: permissionCondShared(req.user) },
},
},
],
},
});
}
@ -116,13 +125,21 @@ export class ServiceController extends Controller {
AND: {
...filterStatus(status),
productGroupId,
productGroup: isSystem(req.user)
OR: isSystem(req.user)
? undefined
: {
registeredBranch: {
OR: permissionCond(req.user),
: [
{
productGroup: {
registeredBranch: { OR: permissionCond(req.user) },
},
},
},
{
shared: true,
productGroup: {
registeredBranch: { OR: permissionCondShared(req.user) },
},
},
],
},
} satisfies Prisma.ServiceWhereInput;