chore: improve and add TSDocs for next release (#14170)

This commit is contained in:
Shahed Nasser
2025-12-01 13:41:31 +02:00
committed by GitHub
parent d9e3965a10
commit 73ae136965
6 changed files with 71 additions and 14 deletions

View File

@@ -4,6 +4,8 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
/**
* This step lists order change actions filtered by action type.
*
* @since v2.11.4
*/
export const listOrderChangeActionsByTypeStep = createStep(
"list-order-change-actions-by-type",

View File

@@ -29,7 +29,12 @@ export type ComputeAdjustmentsForPreviewWorkflowInput = {
/**
* The order's details.
*/
order: OrderDTO & { promotions: PromotionDTO[] }
order: OrderDTO & {
/**
* The promotions applied to the order.
*/
promotions: PromotionDTO[]
}
/**
* The order change's details.
*/
@@ -42,14 +47,14 @@ export const computeAdjustmentsForPreviewWorkflowId =
* This workflow computes adjustments for an order change if the carry over promotions flag is true on the order change.
* If the flag is false, it deletes the existing adjustments replacement actions.
*
* It is currently used as a part of the order edit and exchange flows.
* It's used by the [Add Items to Order Edit Admin API Route](https://docs.medusajs.com/api/admin#order-edits_postordereditsiditems),
* [Add Outbound Items Admin API Route](https://docs.medusajs.com/api/admin#exchanges_postexchangesidoutbounditems),
* and [Add Inbound Items Admin API Route](https://docs.medusajs.com/api/admin#exchanges_postexchangesidinbounditems).
* It is currently used as a part of the order edit and exchange flows. It's used by workflows
* like {@link orderExchangeAddNewItemWorkflow} and {@link orderEditAddNewItemWorkflow}.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to compute adjustments
* in your custom flows.
*
* @since v2.11.4
*
* @example
* const { result } = await computeAdjustmentsForPreviewWorkflow(container)
* .run({
@@ -62,7 +67,6 @@ export const computeAdjustmentsForPreviewWorkflowId =
* id: "orch_123",
* // other order change details...
* },
* exchange_id: "exchange_123", // optional, for exchanges
* }
* })
*

View File

@@ -34,7 +34,33 @@ export type OnCarryPromotionsFlagSetWorkflowInput = {
}
/**
* This step validates that the order change is an exchange and validates promotion allocation.
* This step validates that the order change is an exchange and validates that
* the promotion allocation is valid for carrying over promotions.
*
* :::note
*
* You can retrieve details of the order and order change using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
*
* :::
*
* @since v2.11.4
*
* @example
* const data = validateCarryPromotionsFlagStep({
* order: {
* id: "order_123",
* // other order details...
* },
* orderChange: {
* id: "orch_123",
* // other order change details...
* },
* input: {
* order_change_id: "orch_123",
* carry_over_promotions: true,
* }
* })
*/
export const validateCarryPromotionsFlagStep = createStep(
"validate-carry-promotions-flag",
@@ -114,9 +140,17 @@ export const validateCarryPromotionsFlagStep = createStep(
export const onCarryPromotionsFlagSetId = "on-carry-promotions-flag-set"
/**
* This workflow sets the carry over promotions flag for an order change.
* It validates that the order change is active and is an exchange, validates promotion allocation,
* and either applies or removes promotion adjustments based on the flag value.
* This workflow toggles whether promotions are carried over to outbound items of an exchange.
* It validates that the order change is an exchange and that it's active. It also validates that the promotion allocation
* is valid for carrying over promotions. Finally, it computes adjustments for the order change
* and either applies or removes promotion adjustments based on whether promotions are to be carried over.
*
* This workflow is used by other workflows, such as the {@link updateOrderChangeWorkflow}.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* set the carry over promotions flag for an order change in your custom flows.
*
* @since v2.11.4
*
* @example
* const { result } = await onCarryPromotionsFlagSet(container)
@@ -129,7 +163,7 @@ export const onCarryPromotionsFlagSetId = "on-carry-promotions-flag-set"
*
* @summary
*
* Set the carry over promotions flag for an order change.
* Toggle carrying over promotions to outbound exchange items.
*/
export const onCarryPromotionsFlagSet = createWorkflow(
onCarryPromotionsFlagSetId,

View File

@@ -13,8 +13,13 @@ export const updateOrderChangeWorkflowId = "update-order-change-workflow"
/**
* This workflow updates an order change.
* If the carry_over_promotions flag is provided, it calls onCarryPromotionsFlagSet
* to handle the promotion logic. Otherwise, it updates the order change directly.
* If the `carry_over_promotions` flag is provided, it calls {@link onCarryPromotionsFlagSet}
* to handle the promotion update logic. Otherwise, it updates the order change directly.
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around
* updating an order change and conditionally handling promotion carry-over.
*
* @since v2.11.4
*
* @example
* const { result } = await updateOrderChangeWorkflow(container)
@@ -27,7 +32,7 @@ export const updateOrderChangeWorkflowId = "update-order-change-workflow"
*
* @summary
*
* Update an order change, conditionally handling promotion carry-over if specified.
* Update an order change.
*/
export const updateOrderChangeWorkflow = createWorkflow(
updateOrderChangeWorkflowId,

View File

@@ -27,6 +27,9 @@ const _OrderChange = model
declined_at: model.dateTime().nullable(),
canceled_by: model.text().nullable(),
canceled_at: model.dateTime().nullable(),
/**
* @since v2.11.4
*/
carry_over_promotions: model.boolean().nullable(),
order: model.belongsTo<() => typeof Order>(() => Order, {
mappedBy: "changes",

View File

@@ -9,7 +9,13 @@ const Promotion = model
code: model.text().searchable(),
is_automatic: model.boolean().default(false),
is_tax_inclusive: model.boolean().default(false),
/**
* @since v2.11.4
*/
limit: model.number().nullable(),
/**
* @since v2.11.4
*/
used: model.number().default(0),
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
status: model
@@ -30,6 +36,9 @@ const Promotion = model
pivotTable: "promotion_promotion_rule",
mappedBy: "promotions",
}),
/**
* @since v2.11.4
*/
metadata: model.json().nullable(),
})
.cascades({