diff --git a/packages/modules/requests/src/api/admin/requests/route.ts b/packages/modules/requests/src/api/admin/requests/route.ts index fd2dfb41d..70ab7c914 100644 --- a/packages/modules/requests/src/api/admin/requests/route.ts +++ b/packages/modules/requests/src/api/admin/requests/route.ts @@ -28,7 +28,7 @@ import { ContainerRegistrationKeys } from '@medusajs/framework/utils' * in: query * schema: * type: string - * enum: [product,product_collection,product_category,seller,review_remove,product_type,product_tag,product_update] + * enum: [product,product_collection,product_collection_update,product_category,seller,review_remove,product_type,product_tag,product_update] * required: false * description: Filter by request type * - name: status diff --git a/packages/modules/requests/src/api/admin/requests/validators.ts b/packages/modules/requests/src/api/admin/requests/validators.ts index a8a66896c..a7882be8d 100644 --- a/packages/modules/requests/src/api/admin/requests/validators.ts +++ b/packages/modules/requests/src/api/admin/requests/validators.ts @@ -10,6 +10,7 @@ export const AdminGetRequestsParams = createFindParams({ type: z .enum([ 'product_collection', + 'product_collection_update', 'product_category', 'product', 'seller', diff --git a/packages/modules/requests/src/api/vendor/requests/validators.ts b/packages/modules/requests/src/api/vendor/requests/validators.ts index cacea6bba..f83061ab1 100644 --- a/packages/modules/requests/src/api/vendor/requests/validators.ts +++ b/packages/modules/requests/src/api/vendor/requests/validators.ts @@ -12,6 +12,7 @@ export const VendorGetRequestsParams = createFindParams({ type: z .enum([ 'product_collection', + 'product_collection_update', 'product_category', 'product', 'review_remove', @@ -88,6 +89,41 @@ const ProductCollectionRequest = z.object({ }) }) +/** + * @schema ProductCollectionUpdateRequest + * type: object + * required: + * - type + * - data + * properties: + * type: + * type: string + * description: The type of the request + * enum: [product_collection_update] + * data: + * type: object + * required: + * - collection_id + * properties: + * collection_id: + * type: string + * description: The ID of the existing collection to update + * title: + * type: string + * description: The new title of the product collection + * handle: + * type: string + * description: The new handle of the product collection + */ +const ProductCollectionUpdateRequest = z.object({ + type: z.literal('product_collection_update'), + data: z.object({ + collection_id: z.string(), + title: z.string().optional(), + handle: z.string().optional() + }) +}) + /** * @schema ReviewRemoveRequest * type: object @@ -196,6 +232,7 @@ export const VendorCreateRequest = z.object({ request: z.discriminatedUnion('type', [ ProductCategoryRequest, ProductCollectionRequest, + ProductCollectionUpdateRequest, ReviewRemoveRequest, ProductTypeRequest, ProductTagRequest diff --git a/packages/modules/requests/src/workflows/requests/utils/select-workflow.ts b/packages/modules/requests/src/workflows/requests/utils/select-workflow.ts index 4bf62f63b..898f66b8e 100644 --- a/packages/modules/requests/src/workflows/requests/utils/select-workflow.ts +++ b/packages/modules/requests/src/workflows/requests/utils/select-workflow.ts @@ -1,6 +1,7 @@ import { acceptProductCategoryRequestWorkflow, acceptProductCollectionRequestWorkflow, + acceptProductCollectionUpdateRequestWorkflow, acceptProductRequestWorkflow, acceptProductTagRequestWorkflow, acceptProductTypeRequestWorkflow, @@ -13,6 +14,10 @@ export const getRequestWorkflowByType = (type: string) => { return acceptProductCollectionRequestWorkflow } + if (type === 'product_collection_update') { + return acceptProductCollectionUpdateRequestWorkflow + } + if (type === 'product_category') { return acceptProductCategoryRequestWorkflow } diff --git a/packages/modules/requests/src/workflows/requests/workflows/accept-product-collection-update-request.ts b/packages/modules/requests/src/workflows/requests/workflows/accept-product-collection-update-request.ts new file mode 100644 index 000000000..5da9c0562 --- /dev/null +++ b/packages/modules/requests/src/workflows/requests/workflows/accept-product-collection-update-request.ts @@ -0,0 +1,24 @@ +import { updateCollectionsWorkflow } from '@medusajs/medusa/core-flows' +import { WorkflowResponse, createWorkflow } from '@medusajs/workflows-sdk' + +import { AcceptRequestDTO } from '@mercurjs/framework' + +import { updateRequestWorkflow } from './update-request' + +export const acceptProductCollectionUpdateRequestWorkflow = createWorkflow( + 'accept-product-collection-update-request', + function (input: AcceptRequestDTO) { + const { collection_id, ...updateData } = input.data + + const collection = updateCollectionsWorkflow.runAsStep({ + input: { + selector: { id: collection_id }, + update: updateData + } + }) + + updateRequestWorkflow.runAsStep({ input }) + return new WorkflowResponse(collection[0]) + } +) + diff --git a/packages/modules/requests/src/workflows/requests/workflows/index.ts b/packages/modules/requests/src/workflows/requests/workflows/index.ts index 5fd056cc9..79dd87944 100644 --- a/packages/modules/requests/src/workflows/requests/workflows/index.ts +++ b/packages/modules/requests/src/workflows/requests/workflows/index.ts @@ -3,6 +3,7 @@ export * from "./create-seller-creation-request"; export * from "./update-request"; export * from "./accept-product-category-request"; export * from "./accept-product-collection-request"; +export * from "./accept-product-collection-update-request"; export * from "./accept-product-request"; export * from "./accept-seller-creation-request"; export * from "./accept-review-remove-request";