From 978eb0eee2c2b5beae6e87aaebdb6fe0629d431d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:02:30 +0700 Subject: [PATCH] feat: add support for active only product resolves https://github.com/Frappet/jws-frontend/issues/146 --- src/controllers/04-product-controller.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/controllers/04-product-controller.ts b/src/controllers/04-product-controller.ts index e128cda..b71f955 100644 --- a/src/controllers/04-product-controller.ts +++ b/src/controllers/04-product-controller.ts @@ -130,6 +130,7 @@ export class ProductController extends Controller { @Query() pageSize: number = 30, @Query() orderField?: keyof Product, @Query() orderBy?: "asc" | "desc", + @Query() activeOnly?: boolean, ) { const where = { OR: queryOrNot(query, [ @@ -138,7 +139,18 @@ export class ProductController extends Controller { { code: { contains: query, mode: "insensitive" } }, ]), AND: { - ...filterStatus(status), + ...filterStatus(activeOnly ? Status.ACTIVE : status), + productGroup: { + status: activeOnly ? { not: Status.INACTIVE } : undefined, + registeredBranch: activeOnly + ? { + OR: [ + { headOffice: { status: { not: Status.INACTIVE } } }, + { headOffice: null, status: { not: Status.INACTIVE } }, + ], + } + : undefined, + }, OR: [ ...(productGroupId ? [ @@ -149,13 +161,17 @@ export class ProductController extends Controller { { shared: true, productGroup: { - registeredBranch: { OR: permissionCondCompany(req.user) }, + registeredBranch: { + OR: permissionCondCompany(req.user, { activeOnly }), + }, }, }, { productGroup: { shared: true, - registeredBranch: { OR: permissionCondCompany(req.user) }, + registeredBranch: { + OR: permissionCondCompany(req.user, { activeOnly }), + }, }, }, ], @@ -169,7 +185,7 @@ export class ProductController extends Controller { { productGroup: { id: productGroupId, - registeredBranch: { OR: permissionCondCompany(req.user) }, + registeredBranch: { OR: permissionCondCompany(req.user, { activeOnly }) }, }, }, ]),