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 }) }, }, }, ]),