UNPKG

@medusajs/core-flows

Version:

Set of workflow definitions for Medusa

55 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPromotionsWorkflow = exports.createPromotionsWorkflowId = void 0; const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk"); const steps_1 = require("../steps"); exports.createPromotionsWorkflowId = "create-promotions"; /** * This workflow creates one or more promotions. It's used by the [Create Promotion Admin API Route](https://docs.medusajs.com/api/admin#promotions_postpromotions). * * This workflow has a hook that allows you to perform custom actions on the created promotion. For example, you can pass under `additional_data` custom data that * allows you to create custom data models linked to the promotions. * * You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around creating promotions. * * @example * const { result } = await createPromotionsWorkflow(container) * .run({ * input: { * promotionsData: [ * { * code: "10OFF", * type: "standard", * status: "active", * application_method: { * type: "percentage", * target_type: "items", * allocation: "across", * value: 10, * currency_code: "usd" * } * } * ], * additional_data: { * external_id: "123" * } * } * }) * * @summary * * Create one or more promotions. * * @property hooks.promotionsCreated - This hook is executed after the promotions are created. You can consume this hook to perform custom actions on the created promotions. */ exports.createPromotionsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.createPromotionsWorkflowId, (input) => { const createdPromotions = (0, steps_1.createPromotionsStep)(input.promotionsData); const promotionsCreated = (0, workflows_sdk_1.createHook)("promotionsCreated", { promotions: createdPromotions, additional_data: input.additional_data, }); return new workflows_sdk_1.WorkflowResponse(createdPromotions, { hooks: [promotionsCreated], }); }); //# sourceMappingURL=create-promotions.js.map