fix: active only does not detect if head is not active

This commit is contained in:
Methapon2001 2024-12-06 16:37:56 +07:00
parent 3f04f3c727
commit 76ea340fe5

View file

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