From 76ea340fe5063852cfe4bd454f7aafc196d2b07c Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:37:56 +0700 Subject: [PATCH] fix: active only does not detect if head is not active --- src/controllers/01-branch-controller.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/01-branch-controller.ts b/src/controllers/01-branch-controller.ts index f6fc788..04449c6 100644 --- a/src/controllers/01-branch-controller.ts +++ b/src/controllers/01-branch-controller.ts @@ -253,7 +253,12 @@ export class BranchController extends Controller { ) { const where = { AND: { - ...filterStatus(status), + ...filterStatus(activeOnly ? Status.ACTIVE : status), + AND: activeOnly + ? { + OR: [{ headOffice: { status: { not: Status.INACTIVE } } }, { headOffice: null }], + } + : undefined, headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined), NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined }, OR: permissionCond(req.user, { alwaysIncludeHead: withHead, activeOnly }),