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 }),