Fix/add additionl data to product categories hook (#11226)
* fix: add additional_data to categoriesCreated hooks * fix: restore yarn.lock * fix: add additional_data param in the http validators * fix: add additional_data to updateProductCategoriesWorkflow * Update yarn.lock * fix: fix merge * fix: refert yarn.lock * fix: revert tarn.lock * Create clean-poets-promise.md --------- Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
7
.changeset/clean-poets-promise.md
Normal file
7
.changeset/clean-poets-promise.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/core-flows": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix: add additionl data to product categories hook
|
||||
@@ -65,6 +65,7 @@ export const createProductCategoriesWorkflow = createWorkflow(
|
||||
|
||||
const categoriesCreated = createHook("categoriesCreated", {
|
||||
categories: createdCategories,
|
||||
additional_data: input.additional_data,
|
||||
})
|
||||
|
||||
return new WorkflowResponse(createdCategories, {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { ProductCategoryDTO, ProductCategoryWorkflow } from "@medusajs/framework/types"
|
||||
import {
|
||||
ProductCategoryDTO,
|
||||
ProductCategoryWorkflow,
|
||||
} from "@medusajs/framework/types"
|
||||
import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
@@ -19,10 +22,10 @@ export const updateProductCategoriesWorkflowId = "update-product-categories"
|
||||
/**
|
||||
* This workflow updates product categories matching specified filters. It's used by the
|
||||
* [Update Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategoriesid).
|
||||
*
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update product categories within your custom flows.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateProductCategoriesWorkflow(container)
|
||||
* .run({
|
||||
@@ -35,16 +38,16 @@ export const updateProductCategoriesWorkflowId = "update-product-categories"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
*
|
||||
* Update product categories.
|
||||
*/
|
||||
export const updateProductCategoriesWorkflow = createWorkflow(
|
||||
updateProductCategoriesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<ProductCategoryWorkflow.UpdateProductCategoriesWorkflowInput>
|
||||
) => {
|
||||
) => {
|
||||
const updatedCategories = updateProductCategoriesStep(input)
|
||||
|
||||
const productCategoryIdEvents = transform(
|
||||
@@ -66,11 +69,12 @@ export const updateProductCategoriesWorkflow = createWorkflow(
|
||||
})
|
||||
|
||||
const categoriesUpdated = createHook("categoriesUpdated", {
|
||||
categories: updatedCategories
|
||||
categories: updatedCategories,
|
||||
additional_data: input.additional_data,
|
||||
})
|
||||
|
||||
return new WorkflowResponse(updatedCategories, {
|
||||
hooks: [categoriesUpdated]
|
||||
hooks: [categoriesUpdated],
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { LinkWorkflowInput } from "../../common"
|
||||
import { AdditionalData } from "../../http"
|
||||
import {
|
||||
CreateProductCategoryDTO,
|
||||
FilterableProductCategoryProps,
|
||||
@@ -8,16 +9,16 @@ import {
|
||||
/**
|
||||
* The data to create product categories.
|
||||
*/
|
||||
export interface CreateProductCategoriesWorkflowInput {
|
||||
export type CreateProductCategoriesWorkflowInput = {
|
||||
/**
|
||||
* The product categories to create.
|
||||
*/
|
||||
product_categories: CreateProductCategoryDTO[]
|
||||
}
|
||||
} & AdditionalData
|
||||
/**
|
||||
* The data to update product categories.
|
||||
*/
|
||||
export interface UpdateProductCategoriesWorkflowInput {
|
||||
export type UpdateProductCategoriesWorkflowInput = {
|
||||
/**
|
||||
* The filters to select the product categories to update.
|
||||
*/
|
||||
@@ -26,7 +27,7 @@ export interface UpdateProductCategoriesWorkflowInput {
|
||||
* The data to update in the product categories.
|
||||
*/
|
||||
update: UpdateProductCategoryDTO
|
||||
}
|
||||
} & AdditionalData
|
||||
|
||||
/**
|
||||
* The products to manage of a category.
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
createFindParams,
|
||||
createOperatorMap,
|
||||
createSelectParams,
|
||||
WithAdditionalData,
|
||||
} from "../../utils/validators"
|
||||
|
||||
export type AdminProductCategoryParamsType = z.infer<
|
||||
@@ -44,7 +45,7 @@ export const AdminProductCategoriesParams = createFindParams({
|
||||
.merge(AdminProductCategoriesParamsFields)
|
||||
.merge(applyAndAndOrOperators(AdminProductCategoriesParamsFields))
|
||||
|
||||
export const AdminCreateProductCategory = z
|
||||
export const CreateProductCategory = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
description: z.string().optional(),
|
||||
@@ -57,11 +58,15 @@ export const AdminCreateProductCategory = z
|
||||
})
|
||||
.strict()
|
||||
|
||||
export const AdminCreateProductCategory = WithAdditionalData(
|
||||
CreateProductCategory
|
||||
)
|
||||
|
||||
export type AdminCreateProductCategoryType = z.infer<
|
||||
typeof AdminCreateProductCategory
|
||||
typeof CreateProductCategory
|
||||
>
|
||||
|
||||
export const AdminUpdateProductCategory = z
|
||||
export const UpdateProductCategory = z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
@@ -74,6 +79,10 @@ export const AdminUpdateProductCategory = z
|
||||
})
|
||||
.strict()
|
||||
|
||||
export const AdminUpdateProductCategory = WithAdditionalData(
|
||||
UpdateProductCategory
|
||||
)
|
||||
|
||||
export type AdminUpdateProductCategoryType = z.infer<
|
||||
typeof AdminUpdateProductCategory
|
||||
typeof UpdateProductCategory
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user