feat: shared between company
This commit is contained in:
parent
2fff5f7e47
commit
2c8faef25c
3 changed files with 67 additions and 14 deletions
|
|
@ -41,6 +41,7 @@ function globalAllow(user: RequestWithUser["user"]) {
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return allowList.some((v) => user.roles?.includes(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const permissionCondShared = createPermCondition((_) => true);
|
||||||
const permissionCond = createPermCondition(globalAllow);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
|
|
||||||
|
|
@ -100,9 +101,21 @@ export class ProductController extends Controller {
|
||||||
return await prisma.product.count({
|
return await prisma.product.count({
|
||||||
where: {
|
where: {
|
||||||
productGroupId,
|
productGroupId,
|
||||||
productGroup: isSystem(req.user)
|
OR: isSystem(req.user)
|
||||||
? undefined
|
? undefined
|
||||||
: { registeredBranch: { OR: permissionCond(req.user) } },
|
: [
|
||||||
|
{
|
||||||
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
shared: true,
|
||||||
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCondShared(req.user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -122,9 +135,21 @@ export class ProductController extends Controller {
|
||||||
AND: {
|
AND: {
|
||||||
...filterStatus(status),
|
...filterStatus(status),
|
||||||
productGroupId,
|
productGroupId,
|
||||||
productGroup: isSystem(req.user)
|
OR: isSystem(req.user)
|
||||||
? undefined
|
? undefined
|
||||||
: { registeredBranch: { OR: permissionCond(req.user) } },
|
: [
|
||||||
|
{
|
||||||
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
shared: true,
|
||||||
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCondShared(req.user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
} satisfies Prisma.ProductWhereInput;
|
} satisfies Prisma.ProductWhereInput;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,17 @@ export class ProductGroup extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let companyBefore = (record.registeredBranch.headOffice || record.registeredBranch).code;
|
||||||
|
let companyAfter = branch ? (branch.headOffice || branch).code : false;
|
||||||
|
|
||||||
|
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"Cannot move between different headoffice",
|
||||||
|
"crossCompanyNotPermit",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const result = await prisma.productGroup.update({
|
const result = await prisma.productGroup.update({
|
||||||
include: {
|
include: {
|
||||||
createdBy: true,
|
createdBy: true,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ function globalAllow(user: RequestWithUser["user"]) {
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return allowList.some((v) => user.roles?.includes(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const permissionCondShared = createPermCondition((_) => true);
|
||||||
const permissionCond = createPermCondition(globalAllow);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
|
|
||||||
|
|
@ -89,13 +90,21 @@ export class ServiceController extends Controller {
|
||||||
return await prisma.service.count({
|
return await prisma.service.count({
|
||||||
where: {
|
where: {
|
||||||
productGroupId,
|
productGroupId,
|
||||||
productGroup: isSystem(req.user)
|
OR: isSystem(req.user)
|
||||||
? undefined
|
? 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: {
|
AND: {
|
||||||
...filterStatus(status),
|
...filterStatus(status),
|
||||||
productGroupId,
|
productGroupId,
|
||||||
productGroup: isSystem(req.user)
|
OR: isSystem(req.user)
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: [
|
||||||
registeredBranch: {
|
{
|
||||||
OR: permissionCond(req.user),
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
shared: true,
|
||||||
|
productGroup: {
|
||||||
|
registeredBranch: { OR: permissionCondShared(req.user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
} satisfies Prisma.ServiceWhereInput;
|
} satisfies Prisma.ServiceWhereInput;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue