From d558aa3cf290affdde41cb090fc551f3e2a6f7dd Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 6 Sep 2024 15:10:37 +0700 Subject: [PATCH] fix: wrong condition --- src/middlewares/employee.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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(