From ebdd5924a6e14c7f8824b360fdaee040e1e09a84 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:27:19 +0700 Subject: [PATCH] fix: condition --- src/controllers/product/product-controller.ts | 10 ++++++---- src/controllers/service/service-controller.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/controllers/product/product-controller.ts b/src/controllers/product/product-controller.ts index 0c28c47..c2e6e88 100644 --- a/src/controllers/product/product-controller.ts +++ b/src/controllers/product/product-controller.ts @@ -104,7 +104,7 @@ export class ProductController extends Controller { @Query() query: string = "", @Query() page: number = 1, @Query() pageSize: number = 30, - @Query() branchId?: string, + @Query() registeredBranchId?: string, ) { const filterStatus = (val?: Status) => { if (!val) return {}; @@ -119,9 +119,11 @@ export class ProductController extends Controller { { name: { contains: query }, productTypeId, ...filterStatus(status) }, { detail: { contains: query }, productTypeId, ...filterStatus(status) }, ], - AND: { - OR: [{ registeredBranchId: branchId }, { registeredBranchId: null }], - }, + AND: registeredBranchId + ? { + OR: [{ registeredBranchId: registeredBranchId }, { registeredBranchId: null }], + } + : undefined, } satisfies Prisma.ProductWhereInput; const [result, total] = await prisma.$transaction([ diff --git a/src/controllers/service/service-controller.ts b/src/controllers/service/service-controller.ts index 1170ab7..cb1b4c5 100644 --- a/src/controllers/service/service-controller.ts +++ b/src/controllers/service/service-controller.ts @@ -93,7 +93,7 @@ export class ServiceController extends Controller { @Query() pageSize: number = 30, @Query() status?: Status, @Query() productTypeId?: string, - @Query() branchId?: string, + @Query() registeredBranchId?: string, ) { const filterStatus = (val?: Status) => { if (!val) return {}; @@ -108,9 +108,11 @@ export class ServiceController extends Controller { { name: { contains: query }, productTypeId, ...filterStatus(status) }, { detail: { contains: query }, productTypeId, ...filterStatus(status) }, ], - AND: { - OR: [{ registeredBranchId: branchId }, { registeredBranchId: null }], - }, + AND: registeredBranchId + ? { + OR: [{ registeredBranchId: registeredBranchId }, { registeredBranchId: null }], + } + : undefined, } satisfies Prisma.ServiceWhereInput; const [result, total] = await prisma.$transaction([