feat(medusa, admin-ui): increase tree depth + scope categories on store + allow categories relation in products API (#3450)
What: - increase tree depth in react nestable - scope categories on store queries - allow categories relation in products API RESOLVES CORE-1238 RESOLVES CORE-1237 RESOLVES CORE-1236
This commit is contained in:
@@ -10,3 +10,4 @@ export * from "./calculate-price-tax-amount"
|
||||
export * from "./csv-cell-content-formatter"
|
||||
export * from "./exception-formatter"
|
||||
export * from "./db-aware-column"
|
||||
export * from "./product-category"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { FindOptionsWhere } from "typeorm"
|
||||
import { ProductCategory } from "../../models"
|
||||
import { isDefined } from "medusa-core-utils"
|
||||
|
||||
export const categoryMatchesScope = (
|
||||
category: ProductCategory,
|
||||
query: FindOptionsWhere<ProductCategory>
|
||||
): boolean => {
|
||||
return Object.keys(query ?? {}).every(key => category[key] === query[key])
|
||||
}
|
||||
|
||||
export const fetchCategoryDescendantsIds = (
|
||||
productCategory: ProductCategory,
|
||||
query: FindOptionsWhere<ProductCategory>
|
||||
) => {
|
||||
let result = [productCategory.id]
|
||||
|
||||
;(productCategory.category_children || []).forEach((child) => {
|
||||
if (categoryMatchesScope(child, query)) {
|
||||
result = result.concat(fetchCategoryDescendantsIds(child, query))
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user