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:
@@ -65,7 +65,6 @@ describe("GET /admin/products/:id", () => {
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
"categories",
|
||||
"sales_channels",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
||||
defaultAdminProductRelations.push("sales_channels")
|
||||
}
|
||||
|
||||
if (featureFlagRouter.isFeatureEnabled("product_categories")) {
|
||||
defaultAdminProductRelations.push("categories")
|
||||
}
|
||||
|
||||
route.post(
|
||||
"/",
|
||||
validateSalesChannelsExist((req) => req.body?.sales_channels),
|
||||
@@ -100,7 +104,6 @@ export const defaultAdminProductRelations = [
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
"categories",
|
||||
]
|
||||
|
||||
export const defaultAdminProductFields: (keyof Product)[] = [
|
||||
|
||||
@@ -26,7 +26,9 @@ const route = Router()
|
||||
export default (app, container, config) => {
|
||||
app.use("/store", route)
|
||||
|
||||
const featureFlagRouter = container.resolve("featureFlagRouter")
|
||||
const storeCors = config.store_cors || ""
|
||||
|
||||
route.use(
|
||||
cors({
|
||||
origin: parseCorsOrigins(storeCors),
|
||||
@@ -39,7 +41,7 @@ export default (app, container, config) => {
|
||||
authRoutes(route)
|
||||
collectionRoutes(route)
|
||||
customerRoutes(route, container)
|
||||
productRoutes(route)
|
||||
productRoutes(route, featureFlagRouter)
|
||||
productTagsRoutes(route)
|
||||
productTypesRoutes(route)
|
||||
orderRoutes(route)
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import {
|
||||
defaultStoreProductCategoryRelations,
|
||||
defaultStoreScope,
|
||||
defaultStoreCategoryScope,
|
||||
defaultStoreProductCategoryFields
|
||||
} from ".."
|
||||
import {
|
||||
@@ -31,7 +31,7 @@ describe("GET /store/product-categories/:id", () => {
|
||||
relations: defaultStoreProductCategoryRelations,
|
||||
select: defaultStoreProductCategoryFields,
|
||||
},
|
||||
defaultStoreScope
|
||||
defaultStoreCategoryScope
|
||||
)
|
||||
})
|
||||
|
||||
@@ -59,7 +59,7 @@ describe("GET /store/product-categories/:id", () => {
|
||||
relations: defaultStoreProductCategoryRelations,
|
||||
select: defaultStoreProductCategoryFields,
|
||||
},
|
||||
defaultStoreScope
|
||||
defaultStoreCategoryScope
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Request, Response } from "express"
|
||||
import ProductCategoryService from "../../../../services/product-category"
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { transformTreeNodesWithConfig } from "../../../../utils/transformers/tree"
|
||||
import { defaultStoreScope } from "."
|
||||
import { defaultStoreCategoryScope } from "."
|
||||
|
||||
/**
|
||||
* @oas [get] /store/product-categories/{id}
|
||||
@@ -70,7 +70,7 @@ export default async (req: Request, res: Response) => {
|
||||
const productCategory = await productCategoryService.retrieve(
|
||||
id,
|
||||
retrieveConfig,
|
||||
defaultStoreScope
|
||||
defaultStoreCategoryScope
|
||||
)
|
||||
|
||||
res.status(200).json({
|
||||
@@ -80,7 +80,7 @@ export default async (req: Request, res: Response) => {
|
||||
product_category: transformTreeNodesWithConfig(
|
||||
productCategory,
|
||||
retrieveConfig,
|
||||
defaultStoreScope
|
||||
defaultStoreCategoryScope
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const defaultStoreProductCategoryRelations = [
|
||||
"category_children",
|
||||
]
|
||||
|
||||
export const defaultStoreScope = {
|
||||
export const defaultStoreCategoryScope = {
|
||||
is_internal: false,
|
||||
is_active: true,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Transform } from "class-transformer"
|
||||
import { ProductCategoryService } from "../../../../services"
|
||||
import { extendedFindParamsMixin } from "../../../../types/common"
|
||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
import { defaultStoreScope } from "."
|
||||
import { defaultStoreCategoryScope } from "."
|
||||
|
||||
/**
|
||||
* @oas [get] /store/product-categories
|
||||
@@ -68,14 +68,14 @@ export default async (req: Request, res: Response) => {
|
||||
)
|
||||
|
||||
const selectors = Object.assign(
|
||||
{ ...defaultStoreScope },
|
||||
{ ...defaultStoreCategoryScope },
|
||||
req.filterableFields
|
||||
)
|
||||
|
||||
const [data, count] = await productCategoryService.listAndCount(
|
||||
selectors,
|
||||
req.listConfig,
|
||||
defaultStoreScope
|
||||
defaultStoreCategoryScope
|
||||
)
|
||||
|
||||
const { limit, offset } = req.validatedQuery
|
||||
|
||||
@@ -18,7 +18,13 @@ describe("GET /store/products", () => {
|
||||
it("calls get product from productSerice", () => {
|
||||
expect(ProductServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(ProductServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||
{ status: ["published"] },
|
||||
{
|
||||
status: ["published"],
|
||||
categories: {
|
||||
is_active: true,
|
||||
is_internal: false,
|
||||
}
|
||||
},
|
||||
{
|
||||
relations: defaultStoreProductsRelations,
|
||||
select: defaultStoreProductsFields,
|
||||
@@ -49,7 +55,14 @@ describe("GET /store/products", () => {
|
||||
it("calls list from productSerice", () => {
|
||||
expect(ProductServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(ProductServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||
{ is_giftcard: true, status: ["published"] },
|
||||
{
|
||||
is_giftcard: true,
|
||||
status: ["published"],
|
||||
categories: {
|
||||
is_active: true,
|
||||
is_internal: false,
|
||||
}
|
||||
},
|
||||
{
|
||||
relations: defaultStoreProductsRelations,
|
||||
select: defaultStoreProductsFields,
|
||||
|
||||
@@ -9,10 +9,15 @@ import { validateProductSalesChannelAssociation } from "../../../middlewares/pub
|
||||
import { validateSalesChannelParam } from "../../../middlewares/publishable-api-key/validate-sales-channel-param"
|
||||
import { StoreGetProductsParams } from "./list-products"
|
||||
import { StoreGetProductsProductParams } from "./get-product"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default (app) => {
|
||||
export default (app, featureFlagRouter: FlagRouter) => {
|
||||
if (featureFlagRouter.isFeatureEnabled("product_categories")) {
|
||||
allowedStoreProductsRelations.push("categories")
|
||||
}
|
||||
|
||||
app.use("/products", extendRequestParams, validateSalesChannelParam, route)
|
||||
|
||||
route.use("/:id", validateProductSalesChannelAssociation)
|
||||
|
||||
@@ -21,6 +21,7 @@ import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { Cart, Product } from "../../../../models"
|
||||
import { defaultStoreCategoryScope } from "../product-categories"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products
|
||||
@@ -199,6 +200,12 @@ export default async (req, res) => {
|
||||
|
||||
// get only published products for store endpoint
|
||||
filterableFields["status"] = ["published"]
|
||||
// store APIs only receive active and public categories to query from
|
||||
filterableFields["categories"] = {
|
||||
...(filterableFields.categories || {}),
|
||||
// Store APIs are only allowed to query active and public categories
|
||||
...defaultStoreCategoryScope
|
||||
}
|
||||
|
||||
if (req.publishableApiKeyScopes?.sales_channel_ids.length) {
|
||||
filterableFields.sales_channel_id =
|
||||
|
||||
Reference in New Issue
Block a user