feat: add active branch only for customer

This commit is contained in:
Methapon2001 2024-12-06 18:12:40 +07:00
parent 9630d02924
commit 1b9c71ef6c

View file

@ -20,6 +20,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { isSystem } from "../utils/keycloak";
import {
branchActiveOnlyCond,
branchRelationPermInclude,
createPermCheck,
createPermCondition,
@ -163,6 +164,7 @@ export class CustomerController extends Controller {
@Query() pageSize: number = 30,
@Query() includeBranch: boolean = false,
@Query() company: boolean = false,
@Query() activeBranchOnly?: boolean,
) {
const where = {
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
@ -179,9 +181,11 @@ export class CustomerController extends Controller {
customerType,
...filterStatus(status),
registeredBranch: isSystem(req.user)
? undefined
? branchActiveOnlyCond(activeBranchOnly)
: {
OR: company ? permissionCondCompany(req.user) : permissionCond(req.user),
OR: company
? permissionCondCompany(req.user, { activeOnly: activeBranchOnly })
: permissionCond(req.user, { activeOnly: activeBranchOnly }),
},
},
} satisfies Prisma.CustomerWhereInput;