fix: wrong condition

This commit is contained in:
Methapon Metanipat 2024-09-06 15:10:37 +07:00
parent 5049392caf
commit d558aa3cf2

View file

@ -21,7 +21,12 @@ export function permissionCheck(globalAllow: (user: RequestWithUser["user"]) =>
user: {
where: { userId: req.user.sub },
},
headOffice: {
branch: {
where: {
user: {
some: { userId: req.user.sub },
},
},
include: {
user: {
where: { userId: req.user.sub },
@ -44,8 +49,7 @@ export function permissionCheck(globalAllow: (user: RequestWithUser["user"]) =>
if (!isSystem(req.user)) {
const _branch = employee.customerBranch.customer.registeredBranch;
const affilationBranch = _branch && _branch.user.length !== 0;
const affilationHeadBranch =
_branch && _branch.headOffice && _branch.headOffice.user.length !== 0;
const affilationHeadBranch = _branch && _branch.branch.every((v) => v.user.length !== 0);
if (!globalAllow(req.user)) {
if (!affilationBranch) {
throw new HttpError(