Skip to content

Commit 93cbc6b

Browse files
bouazzaayyoubcarlos-r-l-rodriguesriqwan
authored
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>
1 parent 95eef89 commit 93cbc6b

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

.changeset/clean-poets-promise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/medusa": patch
3+
"@medusajs/core-flows": patch
4+
"@medusajs/types": patch
5+
---
6+
7+
fix: add additionl data to product categories hook

packages/core/core-flows/src/product-category/workflows/create-product-categories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const createProductCategoriesWorkflow = createWorkflow(
6565

6666
const categoriesCreated = createHook("categoriesCreated", {
6767
categories: createdCategories,
68+
additional_data: input.additional_data,
6869
})
6970

7071
return new WorkflowResponse(createdCategories, {

packages/core/core-flows/src/product-category/workflows/update-product-categories.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ProductCategoryDTO, ProductCategoryWorkflow } from "@medusajs/framework/types"
1+
import {
2+
ProductCategoryDTO,
3+
ProductCategoryWorkflow,
4+
} from "@medusajs/framework/types"
25
import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
36
import {
47
WorkflowData,
@@ -19,10 +22,10 @@ export const updateProductCategoriesWorkflowId = "update-product-categories"
1922
/**
2023
* This workflow updates product categories matching specified filters. It's used by the
2124
* [Update Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategoriesid).
22-
*
25+
*
2326
* You can use this workflow within your customizations or your own custom workflows, allowing you to
2427
* update product categories within your custom flows.
25-
*
28+
*
2629
* @example
2730
* const { result } = await updateProductCategoriesWorkflow(container)
2831
* .run({
@@ -35,16 +38,16 @@ export const updateProductCategoriesWorkflowId = "update-product-categories"
3538
* }
3639
* }
3740
* })
38-
*
41+
*
3942
* @summary
40-
*
43+
*
4144
* Update product categories.
4245
*/
4346
export const updateProductCategoriesWorkflow = createWorkflow(
4447
updateProductCategoriesWorkflowId,
4548
(
4649
input: WorkflowData<ProductCategoryWorkflow.UpdateProductCategoriesWorkflowInput>
47-
) => {
50+
) => {
4851
const updatedCategories = updateProductCategoriesStep(input)
4952

5053
const productCategoryIdEvents = transform(
@@ -66,11 +69,12 @@ export const updateProductCategoriesWorkflow = createWorkflow(
6669
})
6770

6871
const categoriesUpdated = createHook("categoriesUpdated", {
69-
categories: updatedCategories
72+
categories: updatedCategories,
73+
additional_data: input.additional_data,
7074
})
7175

7276
return new WorkflowResponse(updatedCategories, {
73-
hooks: [categoriesUpdated]
77+
hooks: [categoriesUpdated],
7478
})
7579
}
7680
)

packages/core/types/src/workflow/product-category/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LinkWorkflowInput } from "../../common"
2+
import { AdditionalData } from "../../http"
23
import {
34
CreateProductCategoryDTO,
45
FilterableProductCategoryProps,
@@ -8,16 +9,16 @@ import {
89
/**
910
* The data to create product categories.
1011
*/
11-
export interface CreateProductCategoriesWorkflowInput {
12+
export type CreateProductCategoriesWorkflowInput = {
1213
/**
1314
* The product categories to create.
1415
*/
1516
product_categories: CreateProductCategoryDTO[]
16-
}
17+
} & AdditionalData
1718
/**
1819
* The data to update product categories.
1920
*/
20-
export interface UpdateProductCategoriesWorkflowInput {
21+
export type UpdateProductCategoriesWorkflowInput = {
2122
/**
2223
* The filters to select the product categories to update.
2324
*/
@@ -26,7 +27,7 @@ export interface UpdateProductCategoriesWorkflowInput {
2627
* The data to update in the product categories.
2728
*/
2829
update: UpdateProductCategoryDTO
29-
}
30+
} & AdditionalData
3031

3132
/**
3233
* The products to manage of a category.

packages/medusa/src/api/admin/product-categories/validators.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createFindParams,
88
createOperatorMap,
99
createSelectParams,
10+
WithAdditionalData,
1011
} from "../../utils/validators"
1112

1213
export type AdminProductCategoryParamsType = z.infer<
@@ -44,7 +45,7 @@ export const AdminProductCategoriesParams = createFindParams({
4445
.merge(AdminProductCategoriesParamsFields)
4546
.merge(applyAndAndOrOperators(AdminProductCategoriesParamsFields))
4647

47-
export const AdminCreateProductCategory = z
48+
export const CreateProductCategory = z
4849
.object({
4950
name: z.string(),
5051
description: z.string().optional(),
@@ -57,11 +58,15 @@ export const AdminCreateProductCategory = z
5758
})
5859
.strict()
5960

61+
export const AdminCreateProductCategory = WithAdditionalData(
62+
CreateProductCategory
63+
)
64+
6065
export type AdminCreateProductCategoryType = z.infer<
61-
typeof AdminCreateProductCategory
66+
typeof CreateProductCategory
6267
>
6368

64-
export const AdminUpdateProductCategory = z
69+
export const UpdateProductCategory = z
6570
.object({
6671
name: z.string().optional(),
6772
description: z.string().optional(),
@@ -74,6 +79,10 @@ export const AdminUpdateProductCategory = z
7479
})
7580
.strict()
7681

82+
export const AdminUpdateProductCategory = WithAdditionalData(
83+
UpdateProductCategory
84+
)
85+
7786
export type AdminUpdateProductCategoryType = z.infer<
78-
typeof AdminUpdateProductCategory
87+
typeof UpdateProductCategory
7988
>

0 commit comments

Comments
 (0)