feat: Revamp of product categories (#7695)

* feat: Normalize the categories interface to match standards

* feat: Revamp the product category implementation

* fix: Adjustments to code and tests around product categories
This commit is contained in:
Stevche Radevski
2024-06-13 09:10:12 +02:00
committed by GitHub
parent fbd8eef18b
commit d862d03de0
35 changed files with 1135 additions and 874 deletions
@@ -1,6 +1,6 @@
import {
deleteProductCategoryWorkflow,
updateProductCategoryWorkflow,
deleteProductCategoriesWorkflow,
updateProductCategoriesWorkflow,
} from "@medusajs/core-flows"
import { AdminProductCategoryResponse } from "@medusajs/types"
import {
@@ -41,9 +41,8 @@ export const POST = async (
) => {
const { id } = req.params
// TODO: Should be converted to bulk update
await updateProductCategoryWorkflow(req.scope).run({
input: { id, data: req.validatedBody },
await updateProductCategoriesWorkflow(req.scope).run({
input: { selector: { id }, update: req.validatedBody },
})
const [category] = await refetchEntities(
@@ -62,8 +61,8 @@ export const DELETE = async (
) => {
const id = req.params.id
await deleteProductCategoryWorkflow(req.scope).run({
input: id,
await deleteProductCategoriesWorkflow(req.scope).run({
input: [id],
})
res.status(200).json({
@@ -1,4 +1,4 @@
import { createProductCategoryWorkflow } from "@medusajs/core-flows"
import { createProductCategoriesWorkflow } from "@medusajs/core-flows"
import {
AdminProductCategoryListResponse,
AdminProductCategoryResponse,
@@ -37,13 +37,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateProductCategoryType>,
res: MedusaResponse<AdminProductCategoryResponse>
) => {
const { result } = await createProductCategoryWorkflow(req.scope).run({
input: { product_category: req.validatedBody },
const { result } = await createProductCategoriesWorkflow(req.scope).run({
input: { product_categories: [req.validatedBody] },
})
const [category] = await refetchEntities(
"product_category",
{ id: result.id, ...req.filterableFields },
{ id: result[0].id, ...req.filterableFields },
req.scope,
req.remoteQueryConfig.fields
)