From b05d2fe9d43c75053423e306d585f9c3416448b3 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:50:15 +0700 Subject: [PATCH] feat: add support for active only service resolves https://github.com/Frappet/jws-frontend/issues/148 --- src/controllers/04-service-controller.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/controllers/04-service-controller.ts b/src/controllers/04-service-controller.ts index 97eb696..0934238 100644 --- a/src/controllers/04-service-controller.ts +++ b/src/controllers/04-service-controller.ts @@ -154,6 +154,7 @@ export class ServiceController extends Controller { @Query() status?: Status, @Query() productGroupId?: string, @Query() fullDetail?: boolean, + @Query() activeOnly?: boolean, ) { const where = { OR: queryOrNot(query, [ @@ -162,20 +163,31 @@ export class ServiceController extends Controller { { code: { contains: query, mode: "insensitive" } }, ]), AND: { - ...filterStatus(status), + ...filterStatus(activeOnly ? Status.ACTIVE : status), productGroupId, + productGroup: { + status: activeOnly ? { not: Status.INACTIVE } : undefined, + registeredBranch: activeOnly + ? { + OR: [ + { headOffice: { status: { not: Status.INACTIVE } } }, + { headOffice: null, status: { not: Status.INACTIVE } }, + ], + } + : undefined, + }, OR: isSystem(req.user) ? undefined : [ { productGroup: { - registeredBranch: { OR: permissionCond(req.user) }, + registeredBranch: { OR: permissionCond(req.user, { activeOnly }) }, }, }, { shared: true, productGroup: { - registeredBranch: { OR: permissionCondShared(req.user) }, + registeredBranch: { OR: permissionCondShared(req.user, { activeOnly }) }, }, }, ],