From 93cbc6b6695f236fa39b66169de971228888f1b9 Mon Sep 17 00:00:00 2001 From: BOUAZZA Ayyoub <53794413+bouazzaayyoub@users.noreply.github.com> Date: Wed, 26 Feb 2025 13:58:01 +0000 Subject: [PATCH] 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 --- .changeset/clean-poets-promise.md | 7 +++++++ .../workflows/create-product-categories.ts | 1 + .../workflows/update-product-categories.ts | 20 +++++++++++-------- .../src/workflow/product-category/index.ts | 9 +++++---- .../admin/product-categories/validators.ts | 17 ++++++++++++---- 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 .changeset/clean-poets-promise.md diff --git a/.changeset/clean-poets-promise.md b/.changeset/clean-poets-promise.md new file mode 100644 index 0000000000..3143b8c414 --- /dev/null +++ b/.changeset/clean-poets-promise.md @@ -0,0 +1,7 @@ +--- +"@medusajs/medusa": patch +"@medusajs/core-flows": patch +"@medusajs/types": patch +--- + +fix: add additionl data to product categories hook diff --git a/packages/core/core-flows/src/product-category/workflows/create-product-categories.ts b/packages/core/core-flows/src/product-category/workflows/create-product-categories.ts index fabd95eb8b..707ee563cc 100644 --- a/packages/core/core-flows/src/product-category/workflows/create-product-categories.ts +++ b/packages/core/core-flows/src/product-category/workflows/create-product-categories.ts @@ -65,6 +65,7 @@ export const createProductCategoriesWorkflow = createWorkflow( const categoriesCreated = createHook("categoriesCreated", { categories: createdCategories, + additional_data: input.additional_data, }) return new WorkflowResponse(createdCategories, { diff --git a/packages/core/core-flows/src/product-category/workflows/update-product-categories.ts b/packages/core/core-flows/src/product-category/workflows/update-product-categories.ts index ac52077416..5c86407113 100644 --- a/packages/core/core-flows/src/product-category/workflows/update-product-categories.ts +++ b/packages/core/core-flows/src/product-category/workflows/update-product-categories.ts @@ -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 - ) => { + ) => { 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], }) } ) diff --git a/packages/core/types/src/workflow/product-category/index.ts b/packages/core/types/src/workflow/product-category/index.ts index 4579153e47..34cd7a72ad 100644 --- a/packages/core/types/src/workflow/product-category/index.ts +++ b/packages/core/types/src/workflow/product-category/index.ts @@ -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. diff --git a/packages/medusa/src/api/admin/product-categories/validators.ts b/packages/medusa/src/api/admin/product-categories/validators.ts index 8da8b13952..f74d7d3b7e 100644 --- a/packages/medusa/src/api/admin/product-categories/validators.ts +++ b/packages/medusa/src/api/admin/product-categories/validators.ts @@ -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 >