diff --git a/src/middlewares/employee.ts b/src/middlewares/employee.ts index 26b63de..87580cc 100644 --- a/src/middlewares/employee.ts +++ b/src/middlewares/employee.ts @@ -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(