From 78e39ae16e6c0815d9e7aa030ae967ed4b849958 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:15:24 +0700 Subject: [PATCH] feat: add active branch only for customer branch --- src/controllers/03-customer-branch-controller.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controllers/03-customer-branch-controller.ts b/src/controllers/03-customer-branch-controller.ts index d830ba3..62f0e30 100644 --- a/src/controllers/03-customer-branch-controller.ts +++ b/src/controllers/03-customer-branch-controller.ts @@ -19,6 +19,7 @@ import prisma from "../db"; import HttpStatus from "../interfaces/http-status"; import { isSystem } from "../utils/keycloak"; import { + branchActiveOnlyCond, branchRelationPermInclude, createPermCheck, createPermCondition, @@ -193,6 +194,7 @@ export class CustomerBranchController extends Controller { @Query() query: string = "", @Query() page: number = 1, @Query() pageSize: number = 30, + @Query() activeRegisBranchOnly?: boolean, ) { const where = { OR: queryOrNot(query, [ @@ -209,11 +211,16 @@ export class CustomerBranchController extends Controller { ]), AND: { customer: isSystem(req.user) - ? { registeredBranchId } + ? { + registeredBranchId, + registeredBranch: branchActiveOnlyCond(activeRegisBranchOnly), + } : { registeredBranch: { AND: { id: registeredBranchId }, - OR: company ? permissionCondCompany(req.user) : permissionCond(req.user), + OR: company + ? permissionCondCompany(req.user, { activeOnly: activeRegisBranchOnly }) + : permissionCond(req.user, { activeOnly: activeRegisBranchOnly }), }, }, customerId,