feat: add active branch only for customer branch

This commit is contained in:
Methapon2001 2024-12-06 18:15:24 +07:00
parent 1b9c71ef6c
commit 78e39ae16e

View file

@ -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<Prisma.CustomerBranchWhereInput[]>(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,