feat(medusa) allow querying category descendants with a param in list endpoint (#3321)

What:

Allowing the list endpoint to return a full tree when requested. 

Why:

When scoped with parent_category_id=null and include_descendant_tree=true, the query cost is fairly low. This allows for fast querying and prevent FE from building out the entire tree from a flat list repeatedly. By default, it is set to false, so this should be an intentional change knowing the costs of doing it for the entire result set. 

How:

When include_descendants_tree is included in the request parameter or the service parameter, we do a loop on results of product categories and do a call to fetch the descendants of that product category. 

RESOLVES CORE-1128
This commit is contained in:
Riqwan Thamir
2023-02-24 08:46:52 +00:00
committed by GitHub
parent ad7f56506f
commit 6323868f65
6 changed files with 102 additions and 11 deletions
@@ -15,6 +15,7 @@ import { extendedFindParamsMixin } from "../../../../types/common"
* - (query) q {string} Query used for searching product category names orhandles.
* - (query) is_internal {boolean} Search for only internal categories.
* - (query) is_active {boolean} Search for only active categories
* - (query) include_descendants_tree {boolean} Include all nested descendants of category
* - (query) parent_category_id {string} Returns categories scoped by parent
* - (query) offset=0 {integer} How many product categories to skip in the result.
* - (query) limit=100 {integer} Limit the number of product categories returned.
@@ -92,6 +93,10 @@ export class AdminGetProductCategoriesParams extends extendedFindParamsMixin({
@IsOptional()
q?: string
@IsString()
@IsOptional()
include_descendants_tree?: boolean
@IsString()
@IsOptional()
is_internal?: boolean