@medusajs/core-flows
Version:
Set of workflow definitions for Medusa
52 lines • 2.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteCollectionsWorkflow = exports.deleteCollectionsWorkflowId = void 0;
const utils_1 = require("@medusajs/framework/utils");
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
const common_1 = require("../../common");
const steps_1 = require("../steps");
exports.deleteCollectionsWorkflowId = "delete-collections";
/**
* This workflow deletes one or more product collections. It's used by the
* [Delete Product Collection Admin API Route](https://docs.medusajs.com/api/admin#collections_deletecollectionsid).
*
* This workflow has a hook that allows you to perform custom actions after the product collections 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-collection deletion.
*
* @example
* const { result } = await deleteCollectionsWorkflow(container)
* .run({
* input: {
* ids: ["pcol_123"],
* }
* })
*
* @summary
*
* Delete one or more product collection.
*
* @property hooks.collectionsDeleted - This hook is executed after the collections are deleted. You can consume this hook to perform custom actions on the deleted collections.
*/
exports.deleteCollectionsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.deleteCollectionsWorkflowId, (input) => {
const deletedCollections = (0, steps_1.deleteCollectionsStep)(input.ids);
const collectionIdEvents = (0, workflows_sdk_1.transform)({ input }, ({ input }) => {
return input.ids?.map((id) => {
return { id };
});
});
(0, workflows_sdk_1.parallelize)((0, common_1.removeRemoteLinkStep)({
[utils_1.Modules.PRODUCT]: { product_collection_id: input.ids },
}), (0, common_1.emitEventStep)({
eventName: utils_1.ProductCollectionWorkflowEvents.DELETED,
data: collectionIdEvents,
}));
const collectionsDeleted = (0, workflows_sdk_1.createHook)("collectionsDeleted", {
ids: input.ids,
});
return new workflows_sdk_1.WorkflowResponse(deletedCollections, {
hooks: [collectionsDeleted],
});
});
//# sourceMappingURL=delete-collections.js.map
;