UNPKG

@medusajs/core-flows

Version:

Set of workflow definitions for Medusa

53 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteProductOptionsWorkflow = exports.deleteProductOptionsWorkflowId = void 0; const utils_1 = require("@medusajs/framework/utils"); const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk"); const emit_event_1 = require("../../common/steps/emit-event"); const remove_remote_links_1 = require("../../common/steps/remove-remote-links"); const steps_1 = require("../steps"); exports.deleteProductOptionsWorkflowId = "delete-product-options"; /** * This workflow deletes one or more product options. It's used by the * [Delete Product Option Admin API Route](https://docs.medusajs.com/api/admin#products_deleteproductsidoptionsoption_id). * * This workflow has a hook that allows you to perform custom actions after the product options are deleted. For example, * you can delete custom records linked to the product colleciton. * * You can also use this workflow within your own custom workflows, allowing you to wrap custom logic around product-option deletion. * * @example * const { result } = await deleteProductOptionsWorkflow(container) * .run({ * input: { * ids: ["poption_123"], * } * }) * * @summary * * Delete one or more product option. * * @property hooks.productOptionsDeleted - This hook is executed after the options are deleted. You can consume this hook to perform custom actions on the deleted options. */ exports.deleteProductOptionsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.deleteProductOptionsWorkflowId, (input) => { const deletedProductOptions = (0, steps_1.deleteProductOptionsStep)(input.ids); const productOptionsDeleted = (0, workflows_sdk_1.createHook)("productOptionsDeleted", { ids: input.ids, }); const optionIdEvents = (0, workflows_sdk_1.transform)({ input }, ({ input }) => { return input.ids?.map((id) => { return { id }; }); }); (0, workflows_sdk_1.parallelize)((0, remove_remote_links_1.removeRemoteLinkStep)({ [utils_1.Modules.PRODUCT]: { product_option_id: input.ids }, }), (0, emit_event_1.emitEventStep)({ eventName: utils_1.ProductOptionWorkflowEvents.DELETED, data: optionIdEvents, })); return new workflows_sdk_1.WorkflowResponse(deletedProductOptions, { hooks: [productOptionsDeleted], }); }); //# sourceMappingURL=delete-product-options.js.map