feat: Add support for category deletion (#7679)

This commit is contained in:
Stevche Radevski
2024-06-11 16:49:42 +02:00
committed by GitHub
parent dd0b9f0805
commit 0e731dbad0
8 changed files with 164 additions and 35 deletions
@@ -1,4 +1,7 @@
import { updateProductCategoryWorkflow } from "@medusajs/core-flows"
import {
deleteProductCategoryWorkflow,
updateProductCategoryWorkflow,
} from "@medusajs/core-flows"
import { AdminProductCategoryResponse } from "@medusajs/types"
import {
AuthenticatedMedusaRequest,
@@ -9,6 +12,7 @@ import {
AdminProductCategoryParamsType,
AdminUpdateProductCategoryType,
} from "../validators"
import { MedusaError } from "@medusajs/utils"
export const GET = async (
req: AuthenticatedMedusaRequest<AdminProductCategoryParamsType>,
@@ -21,6 +25,13 @@ export const GET = async (
req.remoteQueryConfig.fields
)
if (!category) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Product category with id: ${req.params.id} was not found`
)
}
res.json({ product_category: category })
}
@@ -44,3 +55,20 @@ export const POST = async (
res.status(200).json({ product_category: category })
}
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
const id = req.params.id
await deleteProductCategoryWorkflow(req.scope).run({
input: id,
})
res.status(200).json({
id,
object: "product_category",
deleted: true,
})
}
@@ -53,6 +53,11 @@ export const adminProductCategoryRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["DELETE"],
matcher: "/admin/product-categories/:id",
middlewares: [],
},
{
method: ["POST"],
matcher: "/admin/product-categories/:id/products",