diff --git a/packages/core/core-flows/src/definition/cart/steps/refresh-cart-promotions.ts b/packages/core/core-flows/src/definition/cart/steps/refresh-cart-promotions.ts deleted file mode 100644 index 00b249cf9b..0000000000 --- a/packages/core/core-flows/src/definition/cart/steps/refresh-cart-promotions.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { PromotionActions } from "@medusajs/utils" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { updateCartPromotionsWorkflow } from "../workflows/update-cart-promotions" - -export interface RefreshCartPromotionsStepInput { - id: string - promo_codes?: string[] - action?: - | PromotionActions.ADD - | PromotionActions.REMOVE - | PromotionActions.REPLACE -} - -export const refreshCartPromotionsStepId = "refresh-cart-promotions" -/** - * This step refreshes the promotions of a cart. - */ -export const refreshCartPromotionsStep = createStep( - refreshCartPromotionsStepId, - async (data: RefreshCartPromotionsStepInput, { container }) => { - const { promo_codes = [], id, action = PromotionActions.ADD } = data - - await updateCartPromotionsWorkflow(container).run({ - input: { - action, - promoCodes: promo_codes, - cartId: id, - }, - }) - - return new StepResponse(null) - } -) diff --git a/packages/core/core-flows/src/definition/cart/steps/update-tax-lines.ts b/packages/core/core-flows/src/definition/cart/steps/update-tax-lines.ts deleted file mode 100644 index dbfd6547b3..0000000000 --- a/packages/core/core-flows/src/definition/cart/steps/update-tax-lines.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - CartLineItemDTO, - CartShippingMethodDTO, - CartWorkflowDTO, -} from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { updateTaxLinesWorkflow } from "../workflows/update-tax-lines" - -export interface UpdateTaxLinesStepInput { - cart_or_cart_id: CartWorkflowDTO | string - items?: CartLineItemDTO[] - shipping_methods?: CartShippingMethodDTO[] - force_tax_calculation?: boolean -} - -export const updateTaxLinesStepId = "update-tax-lines-step" -/** - * This step updates tax lines of line items and shipping methods. - */ -export const updateTaxLinesStep = createStep( - updateTaxLinesStepId, - async (input: UpdateTaxLinesStepInput, { container }) => { - const { transaction } = await updateTaxLinesWorkflow(container).run({ - input, - }) - - return new StepResponse(null, { transaction }) - }, - async (flow, { container }) => { - if (!flow) { - return - } - - await updateTaxLinesWorkflow(container).cancel({ - transaction: flow.transaction, - }) - } -) diff --git a/packages/core/core-flows/src/definition/cart/workflows/add-shipping-method-to-cart.ts b/packages/core/core-flows/src/definition/cart/workflows/add-shipping-method-to-cart.ts index 4df3528cd5..1b60773dac 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/add-shipping-method-to-cart.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/add-shipping-method-to-cart.ts @@ -9,9 +9,9 @@ import { removeShippingMethodFromCartStep, validateCartShippingOptionsStep, } from "../steps" -import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions" -import { updateTaxLinesStep } from "../steps/update-tax-lines" import { cartFieldsForRefreshSteps } from "../utils/fields" +import { updateCartPromotionsWorkflow } from "./update-cart-promotions" +import { updateTaxLinesWorkflow } from "./update-tax-lines" export interface AddShippingMethodToCartWorkflowInput { cart_id: string @@ -99,11 +99,17 @@ export const addShippingMethodToWorkflow = createWorkflow( shipping_methods: shippingMethodInput, }) - updateTaxLinesStep({ - cart_or_cart_id: input.cart_id, - shipping_methods: shippingMethodsToAdd, + updateTaxLinesWorkflow.runAsStep({ + input: { + cart_or_cart_id: input.cart_id, + shipping_methods: shippingMethodsToAdd, + }, }) - refreshCartPromotionsStep({ id: input.cart_id }) + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: input.cart_id, + }, + }) } ) diff --git a/packages/core/core-flows/src/definition/cart/workflows/add-to-cart.ts b/packages/core/core-flows/src/definition/cart/workflows/add-to-cart.ts index 5bb0e73d8a..c856cd615d 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/add-to-cart.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/add-to-cart.ts @@ -16,8 +16,6 @@ import { refreshCartShippingMethodsStep, updateLineItemsStep, } from "../steps" -import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions" -import { updateTaxLinesStep } from "../steps/update-tax-lines" import { validateVariantPricesStep } from "../steps/validate-variant-prices" import { cartFieldsForRefreshSteps, @@ -26,6 +24,8 @@ import { import { prepareLineItemData } from "../utils/prepare-line-item-data" import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory" import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection" +import { updateCartPromotionsWorkflow } from "./update-cart-promotions" +import { updateTaxLinesWorkflow } from "./update-tax-lines" export const addToCartWorkflowId = "add-to-cart" /** @@ -117,10 +117,19 @@ export const addToCartWorkflow = createWorkflow( parallelize( refreshCartShippingMethodsStep({ cart }), - updateTaxLinesStep({ cart_or_cart_id: input.cart.id, items }) + updateTaxLinesWorkflow.runAsStep({ + input: { + cart_or_cart_id: input.cart.id, + items, + }, + }) ) - refreshCartPromotionsStep({ id: input.cart.id }) + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: input.cart.id, + }, + }) refreshPaymentCollectionForCartWorkflow.runAsStep({ input: { diff --git a/packages/core/core-flows/src/definition/cart/workflows/create-carts.ts b/packages/core/core-flows/src/definition/cart/workflows/create-carts.ts index ce7c140011..6ad6d1b1d0 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/create-carts.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/create-carts.ts @@ -1,8 +1,4 @@ -import { - AdditionalData, - CartDTO, - CreateCartWorkflowInputDTO, -} from "@medusajs/types" +import { AdditionalData, CreateCartWorkflowInputDTO } from "@medusajs/types" import { MedusaError } from "@medusajs/utils" import { WorkflowData, @@ -20,13 +16,13 @@ import { findSalesChannelStep, getVariantPriceSetsStep, } from "../steps" -import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions" -import { updateTaxLinesStep } from "../steps/update-tax-lines" import { validateVariantPricesStep } from "../steps/validate-variant-prices" import { productVariantsFields } from "../utils/fields" import { prepareLineItemData } from "../utils/prepare-line-item-data" import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory" import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection" +import { updateCartPromotionsWorkflow } from "./update-cart-promotions" +import { updateTaxLinesWorkflow } from "./update-tax-lines" // TODO: The createCartWorkflow are missing the following steps: // - Refresh/delete shipping methods (fulfillment module) @@ -151,11 +147,17 @@ export const createCartWorkflow = createWorkflow( const carts = createCartsStep([cartToCreate]) const cart = transform({ carts }, (data) => data.carts?.[0]) - updateTaxLinesStep({ cart_or_cart_id: cart.id }) + updateTaxLinesWorkflow.runAsStep({ + input: { + cart_or_cart_id: cart.id, + }, + }) - refreshCartPromotionsStep({ - id: cart.id, - promo_codes: input.promo_codes, + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: cart.id, + promo_codes: input.promo_codes, + }, }) refreshPaymentCollectionForCartWorkflow.runAsStep({ diff --git a/packages/core/core-flows/src/definition/cart/workflows/update-cart-promotions.ts b/packages/core/core-flows/src/definition/cart/workflows/update-cart-promotions.ts index 6c7b367d19..70459dc559 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/update-cart-promotions.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/update-cart-promotions.ts @@ -18,8 +18,8 @@ import { updateCartPromotionsStep } from "../steps/update-cart-promotions" import { cartFieldsForRefreshSteps } from "../utils/fields" export type UpdateCartPromotionsWorkflowInput = { - promoCodes: string[] - cartId: string + cart_id: string + promo_codes?: string[] action?: | PromotionActions.ADD | PromotionActions.REMOVE @@ -32,17 +32,19 @@ export const updateCartPromotionsWorkflowId = "update-cart-promotions" */ export const updateCartPromotionsWorkflow = createWorkflow( updateCartPromotionsWorkflowId, - (input: WorkflowData): WorkflowData => { + ( + input: WorkflowData + ): WorkflowData => { const cart = useRemoteQueryStep({ entry_point: "cart", fields: cartFieldsForRefreshSteps, - variables: { id: input.cartId }, + variables: { id: input.cart_id }, list: false, }) const promotionCodesToApply = getPromotionCodesToApply({ cart: cart, - promo_codes: input.promoCodes, + promo_codes: input.promo_codes ?? [], action: input.action || PromotionActions.ADD, }) @@ -69,7 +71,7 @@ export const updateCartPromotionsWorkflow = createWorkflow( shippingMethodAdjustmentsToCreate, }), updateCartPromotionsStep({ - id: input.cartId, + id: input.cart_id, promo_codes: computedPromotionCodes, action: PromotionActions.REPLACE, }) diff --git a/packages/core/core-flows/src/definition/cart/workflows/update-cart.ts b/packages/core/core-flows/src/definition/cart/workflows/update-cart.ts index 38ebc0c079..1e2a5c2cba 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/update-cart.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/update-cart.ts @@ -16,10 +16,10 @@ import { refreshCartShippingMethodsStep, updateCartsStep, } from "../steps" -import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions" -import { updateTaxLinesStep } from "../steps/update-tax-lines" import { cartFieldsForRefreshSteps } from "../utils/fields" import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection" +import { updateCartPromotionsWorkflow } from "./update-cart-promotions" +import { updateTaxLinesWorkflow } from "./update-tax-lines" export const updateCartWorkflowId = "update-cart" /** @@ -87,13 +87,19 @@ export const updateCartWorkflow = createWorkflow( parallelize( refreshCartShippingMethodsStep({ cart }), - updateTaxLinesStep({ cart_or_cart_id: carts[0].id }) + updateTaxLinesWorkflow.runAsStep({ + input: { + cart_or_cart_id: carts[0].id, + }, + }) ) - refreshCartPromotionsStep({ - id: input.id, - promo_codes: input.promo_codes, - action: PromotionActions.REPLACE, + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: input.id, + promo_codes: input.promo_codes, + action: PromotionActions.REPLACE, + }, }) refreshPaymentCollectionForCartWorkflow.runAsStep({ diff --git a/packages/core/core-flows/src/definition/cart/workflows/update-line-item-in-cart.ts b/packages/core/core-flows/src/definition/cart/workflows/update-line-item-in-cart.ts index 8064c4f32f..707e0a6810 100644 --- a/packages/core/core-flows/src/definition/cart/workflows/update-line-item-in-cart.ts +++ b/packages/core/core-flows/src/definition/cart/workflows/update-line-item-in-cart.ts @@ -8,7 +8,6 @@ import { import { useRemoteQueryStep } from "../../../common/steps/use-remote-query" import { updateLineItemsStepWithSelector } from "../../line-item/steps" import { refreshCartShippingMethodsStep } from "../steps" -import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions" import { validateVariantPricesStep } from "../steps/validate-variant-prices" import { cartFieldsForRefreshSteps, @@ -16,6 +15,7 @@ import { } from "../utils/fields" import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory" import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection" +import { updateCartPromotionsWorkflow } from "./update-cart-promotions" // TODO: The UpdateLineItemsWorkflow are missing the following steps: // - Validate shipping methods for new items (fulfillment module) @@ -94,7 +94,11 @@ export const updateLineItemInCartWorkflow = createWorkflow( refreshCartShippingMethodsStep({ cart }) - refreshCartPromotionsStep({ id: input.cart.id }) + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: input.cart.id, + }, + }) refreshPaymentCollectionForCartWorkflow.runAsStep({ input: { cart_id: input.cart.id }, diff --git a/packages/core/core-flows/src/definition/line-item/workflows/delete-line-items.ts b/packages/core/core-flows/src/definition/line-item/workflows/delete-line-items.ts index e5e6397fdc..097b3cfe0f 100644 --- a/packages/core/core-flows/src/definition/line-item/workflows/delete-line-items.ts +++ b/packages/core/core-flows/src/definition/line-item/workflows/delete-line-items.ts @@ -1,5 +1,5 @@ import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" -import { refreshCartPromotionsStep } from "../../cart/steps/refresh-cart-promotions" +import { updateCartPromotionsWorkflow } from "../../cart/workflows/update-cart-promotions" import { deleteLineItemsStep } from "../steps/delete-line-items" export type DeleteLineItemsWorkflowInput = { cart_id: string; ids: string[] } @@ -18,6 +18,10 @@ export const deleteLineItemsWorkflow = createWorkflow( (input: WorkflowData) => { deleteLineItemsStep(input.ids) - refreshCartPromotionsStep({ id: input.cart_id }) + updateCartPromotionsWorkflow.runAsStep({ + input: { + cart_id: input.cart_id, + }, + }) } ) diff --git a/packages/core/core-flows/src/order/steps/index.ts b/packages/core/core-flows/src/order/steps/index.ts index a7ea3851b5..16a3575bd6 100644 --- a/packages/core/core-flows/src/order/steps/index.ts +++ b/packages/core/core-flows/src/order/steps/index.ts @@ -34,4 +34,3 @@ export * from "./set-tax-lines-for-items" export * from "./update-order-change-actions" export * from "./update-order-exchanges" export * from "./update-shipping-methods" -export * from "./update-tax-lines" diff --git a/packages/core/core-flows/src/order/steps/update-tax-lines.ts b/packages/core/core-flows/src/order/steps/update-tax-lines.ts deleted file mode 100644 index f075079154..0000000000 --- a/packages/core/core-flows/src/order/steps/update-tax-lines.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { OrderLineItemDTO, OrderShippingMethodDTO } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { updateOrderTaxLinesWorkflow } from "../workflows/update-tax-lines" - -export interface UpdateOrderTaxLinesStepInput { - order_id: string - items?: OrderLineItemDTO[] - shipping_methods?: OrderShippingMethodDTO[] - force_tax_calculation?: boolean -} - -export const updateOrderTaxLinesStepId = "update-order-tax-lines-step" -/** - * This step updates tax lines for an order's line items and shipping methods. - */ -export const updateOrderTaxLinesStep = createStep( - updateOrderTaxLinesStepId, - async (input: UpdateOrderTaxLinesStepInput, { container }) => { - const { transaction } = await updateOrderTaxLinesWorkflow(container).run({ - input, - }) - - return new StepResponse(null, { transaction }) - }, - async (flow, { container }) => { - if (!flow) { - return - } - - await updateOrderTaxLinesWorkflow(container).cancel({ - transaction: flow.transaction, - }) - } -) diff --git a/packages/core/core-flows/src/order/workflows/create-orders.ts b/packages/core/core-flows/src/order/workflows/create-orders.ts index e8c930d2c4..e80143ba48 100644 --- a/packages/core/core-flows/src/order/workflows/create-orders.ts +++ b/packages/core/core-flows/src/order/workflows/create-orders.ts @@ -16,9 +16,10 @@ import { getVariantPriceSetsStep } from "../../definition/cart/steps/get-variant import { validateVariantPricesStep } from "../../definition/cart/steps/validate-variant-prices" import { prepareLineItemData } from "../../definition/cart/utils/prepare-line-item-data" import { confirmVariantInventoryWorkflow } from "../../definition/cart/workflows/confirm-variant-inventory" -import { createOrdersStep, updateOrderTaxLinesStep } from "../steps" +import { createOrdersStep } from "../steps" import { productVariantsFields } from "../utils/fields" import { prepareCustomLineItemData } from "../utils/prepare-custom-line-item-data" +import { updateOrderTaxLinesWorkflow } from "./update-tax-lines" function prepareLineItems(data) { const items = (data.input.items ?? []).map((item) => { @@ -172,14 +173,12 @@ export const createOrdersWorkflow = createWorkflow( const orders = createOrdersStep([orderToCreate]) const order = transform({ orders }, (data) => data.orders?.[0]) - /* TODO: Implement Order promotions - refreshOrderPromotionsStep({ - id: order.id, - promo_codes: input.promo_codes, + updateOrderTaxLinesWorkflow.runAsStep({ + input: { + order_id: order.id, + }, }) - */ - updateOrderTaxLinesStep({ order_id: order.id }) const orderCreated = createHook("orderCreated", { order, additional_data: input.additional_data, diff --git a/packages/core/core-flows/src/price-list/steps/create-price-list-prices-workflow.ts b/packages/core/core-flows/src/price-list/steps/create-price-list-prices-workflow.ts deleted file mode 100644 index cba2162113..0000000000 --- a/packages/core/core-flows/src/price-list/steps/create-price-list-prices-workflow.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CreatePriceListPricesWorkflowDTO } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { createPriceListPricesWorkflow } from "../workflows/create-price-list-prices" - -export const createPriceListPricesWorkflowStepId = - "create-price-list-prices-workflow-step" -/** - * This step creates prices for price lists. - */ -export const createPriceListPricesWorkflowStep = createStep( - createPriceListPricesWorkflowStepId, - async (data: CreatePriceListPricesWorkflowDTO[], { container }) => { - const { transaction, result: created } = - await createPriceListPricesWorkflow(container).run({ input: { data } }) - - return new StepResponse(created, transaction) - }, - - async (transaction, { container }) => { - if (!transaction) { - return - } - - await createPriceListPricesWorkflow(container).cancel({ transaction }) - } -) diff --git a/packages/core/core-flows/src/price-list/steps/index.ts b/packages/core/core-flows/src/price-list/steps/index.ts index 771372963b..74f4aebfeb 100644 --- a/packages/core/core-flows/src/price-list/steps/index.ts +++ b/packages/core/core-flows/src/price-list/steps/index.ts @@ -1,12 +1,9 @@ export * from "./create-price-list-prices" -export * from "./create-price-list-prices-workflow" export * from "./create-price-lists" export * from "./delete-price-lists" export * from "./get-existing-price-lists-price-ids" export * from "./remove-price-list-prices" -export * from "./remove-price-list-prices-workflow" export * from "./update-price-list-prices" -export * from "./update-price-list-prices-workflow" export * from "./update-price-lists" export * from "./validate-price-lists" export * from "./validate-variant-price-links" diff --git a/packages/core/core-flows/src/price-list/steps/remove-price-list-prices-workflow.ts b/packages/core/core-flows/src/price-list/steps/remove-price-list-prices-workflow.ts deleted file mode 100644 index af8618862f..0000000000 --- a/packages/core/core-flows/src/price-list/steps/remove-price-list-prices-workflow.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { removePriceListPricesWorkflow } from "../workflows/remove-price-list-prices" - -export const removePriceListPricesWorkflowStepId = - "remove-price-list-prices-workflow" -/** - * This step removes prices from price lists. - */ -export const removePriceListPricesWorkflowStep = createStep( - removePriceListPricesWorkflowStepId, - async (ids: string[], { container }) => { - const { transaction, result: updated } = - await removePriceListPricesWorkflow(container).run({ input: { ids } }) - - return new StepResponse(updated, transaction) - }, - - async (transaction, { container }) => { - if (!transaction) { - return - } - - await removePriceListPricesWorkflow(container).cancel({ transaction }) - } -) diff --git a/packages/core/core-flows/src/price-list/steps/update-price-list-prices-workflow.ts b/packages/core/core-flows/src/price-list/steps/update-price-list-prices-workflow.ts deleted file mode 100644 index f87beb172b..0000000000 --- a/packages/core/core-flows/src/price-list/steps/update-price-list-prices-workflow.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { UpdatePriceListPricesWorkflowDTO } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { updatePriceListPricesWorkflow } from "../workflows/update-price-list-prices" - -export const updatePriceListPricesWorkflowStepId = - "update-price-list-prices-workflow" -/** - * This step updates price lists' prices. - */ -export const updatePriceListPricesWorkflowStep = createStep( - updatePriceListPricesWorkflowStepId, - async (data: UpdatePriceListPricesWorkflowDTO[], { container }) => { - const { transaction, result: updated } = - await updatePriceListPricesWorkflow(container).run({ input: { data } }) - - return new StepResponse(updated, transaction) - }, - - async (transaction, { container }) => { - if (!transaction) { - return - } - - await updatePriceListPricesWorkflow(container).cancel({ transaction }) - } -) diff --git a/packages/core/core-flows/src/price-list/workflows/batch-price-list-prices.ts b/packages/core/core-flows/src/price-list/workflows/batch-price-list-prices.ts index 5e0b841fce..00fa8555da 100644 --- a/packages/core/core-flows/src/price-list/workflows/batch-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/workflows/batch-price-list-prices.ts @@ -9,9 +9,9 @@ import { parallelize, transform, } from "@medusajs/workflows-sdk" -import { createPriceListPricesWorkflowStep } from "../steps/create-price-list-prices-workflow" -import { removePriceListPricesWorkflowStep } from "../steps/remove-price-list-prices-workflow" -import { updatePriceListPricesWorkflowStep } from "../steps/update-price-list-prices-workflow" +import { createPriceListPricesWorkflow } from "./create-price-list-prices" +import { removePriceListPricesWorkflow } from "./remove-price-list-prices" +import { updatePriceListPricesWorkflow } from "./update-price-list-prices" export const batchPriceListPricesWorkflowId = "batch-price-list-prices" /** @@ -33,9 +33,21 @@ export const batchPriceListPricesWorkflow = createWorkflow( ]) const [created, updated, deleted] = parallelize( - createPriceListPricesWorkflowStep(createInput), - updatePriceListPricesWorkflowStep(updateInput), - removePriceListPricesWorkflowStep(input.data.delete) + createPriceListPricesWorkflow.runAsStep({ + input: { + data: createInput, + }, + }), + updatePriceListPricesWorkflow.runAsStep({ + input: { + data: updateInput, + }, + }), + removePriceListPricesWorkflow.runAsStep({ + input: { + ids: input.data.delete, + }, + }) ) return new WorkflowResponse( diff --git a/packages/core/core-flows/src/promotion/steps/create-promotion-rules-workflow.ts b/packages/core/core-flows/src/promotion/steps/create-promotion-rules-workflow.ts deleted file mode 100644 index 602c991a5c..0000000000 --- a/packages/core/core-flows/src/promotion/steps/create-promotion-rules-workflow.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { AddPromotionRulesWorkflowDTO } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { createPromotionRulesWorkflow } from "../workflows/create-promotion-rules" - -export const createPromotionRulesWorkflowStepId = - "create-promotion-rules-workflow" -/** - * This step creates promotion rules using the {@link createPromotionRulesWorkflow}. - */ -export const createPromotionRulesWorkflowStep = createStep( - createPromotionRulesWorkflowStepId, - async (data: AddPromotionRulesWorkflowDTO, { container }) => { - const { - transaction, - result: created, - errors, - } = await createPromotionRulesWorkflow(container).run({ - input: data, - throwOnError: false, - }) - - if (errors?.length) { - throw errors[0].error - } - - return new StepResponse(created, transaction) - }, - - async (transaction, { container }) => { - if (!transaction) { - return - } - - await createPromotionRulesWorkflow(container).cancel({ transaction }) - } -) diff --git a/packages/core/core-flows/src/promotion/steps/update-promotion-rules-workflow.ts b/packages/core/core-flows/src/promotion/steps/update-promotion-rules-workflow.ts deleted file mode 100644 index cdf0c51750..0000000000 --- a/packages/core/core-flows/src/promotion/steps/update-promotion-rules-workflow.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { UpdatePromotionRulesWorkflowDTO } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { updatePromotionRulesWorkflow } from "../workflows/update-promotion-rules" - -export const updatePromotionRulesWorkflowStepId = - "update-promotion-rules-workflow" -/** - * This step updates promotion rules using the {@link updatePromotionRulesWorkflow}. - */ -export const updatePromotionRulesWorkflowStep = createStep( - updatePromotionRulesWorkflowStepId, - async (data: UpdatePromotionRulesWorkflowDTO, { container }) => { - const { - transaction, - result: updated, - errors, - } = await updatePromotionRulesWorkflow(container).run({ - input: data, - throwOnError: false, - }) - - if (errors?.length) { - throw errors[0].error - } - - return new StepResponse(updated, transaction) - }, - - async (transaction, { container }) => { - if (!transaction) { - return - } - - await updatePromotionRulesWorkflow(container).cancel({ transaction }) - } -) diff --git a/packages/core/core-flows/src/promotion/workflows/batch-promotion-rules.ts b/packages/core/core-flows/src/promotion/workflows/batch-promotion-rules.ts index 307e6b3df7..a8bb7a999d 100644 --- a/packages/core/core-flows/src/promotion/workflows/batch-promotion-rules.ts +++ b/packages/core/core-flows/src/promotion/workflows/batch-promotion-rules.ts @@ -5,6 +5,7 @@ import { PromotionRuleDTO, UpdatePromotionRuleDTO, } from "@medusajs/types" +import { RuleType } from "@medusajs/utils" import { WorkflowData, WorkflowResponse, @@ -12,10 +13,9 @@ import { parallelize, transform, } from "@medusajs/workflows-sdk" -import { RuleType } from "@medusajs/utils" -import { createPromotionRulesWorkflowStep } from "../steps/create-promotion-rules-workflow" -import { updatePromotionRulesWorkflowStep } from "../steps/update-promotion-rules-workflow" import { deletePromotionRulesWorkflowStep } from "../steps/delete-promotion-rules-workflow" +import { createPromotionRulesWorkflow } from "./create-promotion-rules" +import { updatePromotionRulesWorkflow } from "./update-promotion-rules" export const batchPromotionRulesWorkflowId = "batch-promotion-rules" /** @@ -46,8 +46,12 @@ export const batchPromotionRulesWorkflow = createWorkflow( })) const [created, updated, deleted] = parallelize( - createPromotionRulesWorkflowStep(createInput), - updatePromotionRulesWorkflowStep(updateInput), + createPromotionRulesWorkflow.runAsStep({ + input: createInput, + }), + updatePromotionRulesWorkflow.runAsStep({ + input: updateInput, + }), deletePromotionRulesWorkflowStep(deleteInput) ) diff --git a/packages/core/types/src/workflow/order/index.ts b/packages/core/types/src/workflow/order/index.ts index 005083f337..91adb48a81 100644 --- a/packages/core/types/src/workflow/order/index.ts +++ b/packages/core/types/src/workflow/order/index.ts @@ -14,4 +14,3 @@ export * from "./receive-return" export * from "./request-item-return" export * from "./shipping-method" export * from "./update-return" - diff --git a/packages/core/types/src/workflow/order/items.ts b/packages/core/types/src/workflow/order/items.ts index a8bacdc86a..21a6e45bfb 100644 --- a/packages/core/types/src/workflow/order/items.ts +++ b/packages/core/types/src/workflow/order/items.ts @@ -30,6 +30,11 @@ export interface OrderExchangeAddNewItemWorkflowInput { items: NewItem[] } +export interface OrderEditAddNewItemWorkflowInput { + order_id: string + items: NewItem[] +} + export interface OrderAddLineItemWorkflowInput { order_id: string items: NewItem[] diff --git a/packages/medusa/src/api/store/carts/[id]/promotions/route.ts b/packages/medusa/src/api/store/carts/[id]/promotions/route.ts index f2ededec03..3078b4a375 100644 --- a/packages/medusa/src/api/store/carts/[id]/promotions/route.ts +++ b/packages/medusa/src/api/store/carts/[id]/promotions/route.ts @@ -16,8 +16,8 @@ export const POST = async ( await workflow.run({ input: { - promoCodes: payload.promo_codes, - cartId: req.params.id, + promo_codes: payload.promo_codes, + cart_id: req.params.id, action: PromotionActions.ADD, }, }) @@ -40,8 +40,8 @@ export const DELETE = async ( await workflow.run({ input: { - promoCodes: payload.promo_codes, - cartId: req.params.id, + promo_codes: payload.promo_codes, + cart_id: req.params.id, action: PromotionActions.REMOVE, }, })