fix(core-flows): customer id filter not working in getOrderDetails (#13695)
As discussed, fixed the get order detail and also changed the remotequery to graph a bunch of workflows
This commit is contained in:
1 parent
82f3b0413a
commit
924564bee5
17 files changed
+219
-144
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(core-flows): customer id filter not working in getOrderDetails
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { getOrderDetailWorkflow } from "@medusajs/core-flows"
|
||||||
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||||
|
import { OrderDTO } from "@medusajs/types"
|
||||||
|
import { createOrderFixture, prepareDataFixtures } from "./__fixtures__"
|
||||||
|
|
||||||
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
|
medusaIntegrationTestRunner({
|
||||||
|
env: {},
|
||||||
|
testSuite: ({ getContainer }) => {
|
||||||
|
let container
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
container = getContainer()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("Get order detail workflow", () => {
|
||||||
|
let order: OrderDTO
|
||||||
|
|
||||||
|
describe("createOrderChangeWorkflow", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const fixtures = await prepareDataFixtures({
|
||||||
|
container,
|
||||||
|
})
|
||||||
|
|
||||||
|
order = await createOrderFixture({
|
||||||
|
container,
|
||||||
|
product: fixtures.product,
|
||||||
|
location: fixtures.location,
|
||||||
|
inventoryItem: fixtures.inventoryItem,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should get an order based on filters", async () => {
|
||||||
|
const response = await getOrderDetailWorkflow(container).run({
|
||||||
|
input: {
|
||||||
|
fields: [],
|
||||||
|
filters: {
|
||||||
|
customer_id: order.customer_id ?? "",
|
||||||
|
},
|
||||||
|
order_id: order.id,
|
||||||
|
},
|
||||||
|
throwOnError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw an error when getting order if none is found with the provided customer id", async () => {
|
||||||
|
const {
|
||||||
|
errors: [error],
|
||||||
|
} = await getOrderDetailWorkflow(container).run({
|
||||||
|
input: {
|
||||||
|
fields: [],
|
||||||
|
filters: {
|
||||||
|
customer_id: "wrong-id",
|
||||||
|
},
|
||||||
|
order_id: order.id,
|
||||||
|
},
|
||||||
|
throwOnError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(error.error).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
message: `Order id not found: ${order.id}`,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -21,7 +21,7 @@ import { requiredVariantFieldsForInventoryConfirmation } from "../../cart/utils/
|
|||||||
import { pricingContextResult } from "../../cart/utils/schemas"
|
import { pricingContextResult } from "../../cart/utils/schemas"
|
||||||
import { confirmVariantInventoryWorkflow } from "../../cart/workflows/confirm-variant-inventory"
|
import { confirmVariantInventoryWorkflow } from "../../cart/workflows/confirm-variant-inventory"
|
||||||
import { getVariantsAndItemsWithPrices } from "../../cart/workflows/get-variants-and-items-with-prices"
|
import { getVariantsAndItemsWithPrices } from "../../cart/workflows/get-variants-and-items-with-prices"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import { createOrderLineItemsStep } from "../steps"
|
import { createOrderLineItemsStep } from "../steps"
|
||||||
import { productVariantsFields } from "../utils/fields"
|
import { productVariantsFields } from "../utils/fields"
|
||||||
|
|
||||||
@@ -98,8 +98,9 @@ export const addOrderLineItemsWorkflow = createWorkflow(
|
|||||||
OrderWorkflow.OrderAddLineItemWorkflowInput & AdditionalData
|
OrderWorkflow.OrderAddLineItemWorkflowInput & AdditionalData
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const order = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "orders",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"sales_channel_id",
|
"sales_channel_id",
|
||||||
@@ -108,9 +109,7 @@ export const addOrderLineItemsWorkflow = createWorkflow(
|
|||||||
"email",
|
"email",
|
||||||
"currency_code",
|
"currency_code",
|
||||||
],
|
],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
|
||||||
throw_if_key_not_found: true,
|
|
||||||
}).config({ name: "order-query" })
|
}).config({ name: "order-query" })
|
||||||
|
|
||||||
const variantIds = transform({ input }, (data) => {
|
const variantIds = transform({ input }, (data) => {
|
||||||
|
|||||||
@@ -16,15 +16,19 @@ import {
|
|||||||
OrderWorkflowEvents,
|
OrderWorkflowEvents,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createHook,
|
createHook,
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import {
|
||||||
|
emitEventStep,
|
||||||
|
useQueryGraphStep,
|
||||||
|
useRemoteQueryStep,
|
||||||
|
} from "../../common"
|
||||||
import { cancelFulfillmentWorkflow } from "../../fulfillment"
|
import { cancelFulfillmentWorkflow } from "../../fulfillment"
|
||||||
import { adjustInventoryLevelsStep } from "../../inventory"
|
import { adjustInventoryLevelsStep } from "../../inventory"
|
||||||
import { cancelOrderFulfillmentStep } from "../steps/cancel-fulfillment"
|
import { cancelOrderFulfillmentStep } from "../steps/cancel-fulfillment"
|
||||||
@@ -32,8 +36,10 @@ import {
|
|||||||
throwIfItemsDoesNotExistsInOrder,
|
throwIfItemsDoesNotExistsInOrder,
|
||||||
throwIfOrderIsCancelled,
|
throwIfOrderIsCancelled,
|
||||||
} from "../utils/order-validation"
|
} from "../utils/order-validation"
|
||||||
import { createReservationsStep } from "../../reservation"
|
import {
|
||||||
import { updateReservationsStep } from "../../reservation"
|
createReservationsStep,
|
||||||
|
updateReservationsStep,
|
||||||
|
} from "../../reservation"
|
||||||
|
|
||||||
type OrderItemWithVariantDTO = OrderLineItemDTO & {
|
type OrderItemWithVariantDTO = OrderLineItemDTO & {
|
||||||
variant?: ProductVariantDTO & {
|
variant?: ProductVariantDTO & {
|
||||||
@@ -307,9 +313,9 @@ export const cancelOrderFulfillmentWorkflowId = "cancel-order-fulfillment"
|
|||||||
export const cancelOrderFulfillmentWorkflow = createWorkflow(
|
export const cancelOrderFulfillmentWorkflow = createWorkflow(
|
||||||
cancelOrderFulfillmentWorkflowId,
|
cancelOrderFulfillmentWorkflowId,
|
||||||
(input: WorkflowData<CancelOrderFulfillmentWorkflowInput>) => {
|
(input: WorkflowData<CancelOrderFulfillmentWorkflowInput>) => {
|
||||||
const order: OrderDTO & { fulfillments: FulfillmentDTO[] } =
|
const { data: order } = useQueryGraphStep({
|
||||||
useRemoteQueryStep({
|
entity: "order",
|
||||||
entry_point: "orders",
|
filters: { id: input.order_id },
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"status",
|
"status",
|
||||||
@@ -328,10 +334,8 @@ export const cancelOrderFulfillmentWorkflow = createWorkflow(
|
|||||||
"fulfillments.items.line_item_id",
|
"fulfillments.items.line_item_id",
|
||||||
"fulfillments.items.inventory_item_id",
|
"fulfillments.items.inventory_item_id",
|
||||||
],
|
],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
}).config({ name: "get-order" })
|
||||||
throw_if_key_not_found: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
cancelOrderFulfillmentValidateOrder({ order, input })
|
cancelOrderFulfillmentValidateOrder({ order, input })
|
||||||
|
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ import {
|
|||||||
PaymentCollectionDTO,
|
PaymentCollectionDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
|
deepFlatMap,
|
||||||
MathBN,
|
MathBN,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
OrderWorkflowEvents,
|
OrderWorkflowEvents,
|
||||||
PaymentCollectionStatus,
|
PaymentCollectionStatus,
|
||||||
deepFlatMap,
|
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createHook,
|
createHook,
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
when,
|
when,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { emitEventStep, useQueryGraphStep } from "../../common"
|
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||||
import { updatePaymentCollectionStep } from "../../payment-collection"
|
import { updatePaymentCollectionStep } from "../../payment-collection"
|
||||||
@@ -68,9 +68,7 @@ export type CancelValidateOrderStepInput = {
|
|||||||
*/
|
*/
|
||||||
export const cancelValidateOrder = createStep(
|
export const cancelValidateOrder = createStep(
|
||||||
"cancel-validate-order",
|
"cancel-validate-order",
|
||||||
({
|
({ order }: CancelValidateOrderStepInput) => {
|
||||||
order,
|
|
||||||
}: CancelValidateOrderStepInput) => {
|
|
||||||
const order_ = order as OrderDTO & {
|
const order_ = order as OrderDTO & {
|
||||||
payment_collections: PaymentCollectionDTO[]
|
payment_collections: PaymentCollectionDTO[]
|
||||||
fulfillments: FulfillmentDTO[]
|
fulfillments: FulfillmentDTO[]
|
||||||
@@ -128,7 +126,7 @@ export const cancelOrderWorkflow = createWorkflow(
|
|||||||
cancelOrderWorkflowId,
|
cancelOrderWorkflowId,
|
||||||
(input: WorkflowData<OrderWorkflow.CancelOrderWorkflowInput>) => {
|
(input: WorkflowData<OrderWorkflow.CancelOrderWorkflowInput>) => {
|
||||||
const orderQuery = useQueryGraphStep({
|
const orderQuery = useQueryGraphStep({
|
||||||
entity: "orders",
|
entity: "order",
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"status",
|
"status",
|
||||||
@@ -143,7 +141,7 @@ export const cancelOrderWorkflow = createWorkflow(
|
|||||||
],
|
],
|
||||||
filters: { id: input.order_id },
|
filters: { id: input.order_id },
|
||||||
options: { throwIfKeyNotFound: true },
|
options: { throwIfKeyNotFound: true },
|
||||||
}).config({ name: "get-cart" })
|
}).config({ name: "get-order" })
|
||||||
|
|
||||||
const order = transform(
|
const order = transform(
|
||||||
{ orderQuery },
|
{ orderQuery },
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ import {
|
|||||||
OrderWorkflowEvents,
|
OrderWorkflowEvents,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createHook,
|
createHook,
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import {
|
import {
|
||||||
createRemoteLinkStep,
|
createRemoteLinkStep,
|
||||||
emitEventStep,
|
emitEventStep,
|
||||||
|
useQueryGraphStep,
|
||||||
useRemoteQueryStep,
|
useRemoteQueryStep,
|
||||||
} from "../../common"
|
} from "../../common"
|
||||||
import { createFulfillmentWorkflow } from "../../fulfillment"
|
import { createFulfillmentWorkflow } from "../../fulfillment"
|
||||||
@@ -393,8 +394,9 @@ export const createOrderFulfillmentWorkflowId = "create-order-fulfillment"
|
|||||||
export const createOrderFulfillmentWorkflow = createWorkflow(
|
export const createOrderFulfillmentWorkflow = createWorkflow(
|
||||||
createOrderFulfillmentWorkflowId,
|
createOrderFulfillmentWorkflowId,
|
||||||
(input: WorkflowData<CreateOrderFulfillmentWorkflowInput>) => {
|
(input: WorkflowData<CreateOrderFulfillmentWorkflowInput>) => {
|
||||||
const order: OrderDTO = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "orders",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"display_id",
|
"display_id",
|
||||||
@@ -444,10 +446,8 @@ export const createOrderFulfillmentWorkflow = createWorkflow(
|
|||||||
"shipping_methods.data",
|
"shipping_methods.data",
|
||||||
"shipping_methods.amount",
|
"shipping_methods.amount",
|
||||||
],
|
],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
}).config({ name: "get-order" })
|
||||||
throw_if_key_not_found: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
createFulfillmentValidateOrder({ order, inputItems: input.items })
|
createFulfillmentValidateOrder({ order, inputItems: input.items })
|
||||||
|
|
||||||
|
|||||||
+11
-14
@@ -11,7 +11,7 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import { updatePaymentCollectionStep } from "../../payment-collection"
|
import { updatePaymentCollectionStep } from "../../payment-collection"
|
||||||
import { cancelPaymentCollectionWorkflow } from "../../payment-collection/workflows/cancel-payment-collection"
|
import { cancelPaymentCollectionWorkflow } from "../../payment-collection/workflows/cancel-payment-collection"
|
||||||
import { createOrderPaymentCollectionWorkflow } from "./create-order-payment-collection"
|
import { createOrderPaymentCollectionWorkflow } from "./create-order-payment-collection"
|
||||||
@@ -63,18 +63,17 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
|||||||
amount?: number
|
amount?: number
|
||||||
}>
|
}>
|
||||||
) => {
|
) => {
|
||||||
const order = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "order",
|
entity: "order",
|
||||||
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
||||||
variables: { id: input.order_id },
|
filters: { id: input.order_id },
|
||||||
throw_if_key_not_found: true,
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const orderPaymentCollections = useRemoteQueryStep({
|
const { data: orderPaymentCollections } = useQueryGraphStep({
|
||||||
entry_point: "order_payment_collection",
|
entity: "order_payment_collection",
|
||||||
fields: ["payment_collection_id"],
|
fields: ["payment_collection_id"],
|
||||||
variables: { order_id: order.id },
|
filters: { order_id: order.id },
|
||||||
}).config({ name: "order-payment-collection-query" })
|
}).config({ name: "order-payment-collection-query" })
|
||||||
|
|
||||||
const orderPaymentCollectionIds = transform(
|
const orderPaymentCollectionIds = transform(
|
||||||
@@ -83,10 +82,9 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
|||||||
orderPaymentCollections.map((opc) => opc.payment_collection_id)
|
orderPaymentCollections.map((opc) => opc.payment_collection_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
const existingPaymentCollection = useRemoteQueryStep({
|
const { data: existingPaymentCollection } = useQueryGraphStep({
|
||||||
entry_point: "payment_collection",
|
entity: "payment_collection",
|
||||||
fields: ["id", "status"],
|
fields: ["id", "status"],
|
||||||
variables: {
|
|
||||||
filters: {
|
filters: {
|
||||||
id: orderPaymentCollectionIds,
|
id: orderPaymentCollectionIds,
|
||||||
status: [
|
status: [
|
||||||
@@ -98,8 +96,7 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
|||||||
PaymentCollectionStatus.PARTIALLY_AUTHORIZED,
|
PaymentCollectionStatus.PARTIALLY_AUTHORIZED,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
options: { isList: false },
|
||||||
list: false,
|
|
||||||
}).config({ name: "payment-collection-query" })
|
}).config({ name: "payment-collection-query" })
|
||||||
|
|
||||||
const shouldRecreate = transform(
|
const shouldRecreate = transform(
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { createPaymentCollectionsStep } from "../../cart"
|
import { createPaymentCollectionsStep } from "../../cart"
|
||||||
import { createRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
import { createRemoteLinkStep, useQueryGraphStep } from "../../common"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the payment collection to create.
|
* The details of the payment collection to create.
|
||||||
@@ -47,13 +47,12 @@ export const createOrderPaymentCollectionWorkflowId =
|
|||||||
export const createOrderPaymentCollectionWorkflow = createWorkflow(
|
export const createOrderPaymentCollectionWorkflow = createWorkflow(
|
||||||
createOrderPaymentCollectionWorkflowId,
|
createOrderPaymentCollectionWorkflowId,
|
||||||
(input: WorkflowData<CreateOrderPaymentCollectionWorkflowInput>) => {
|
(input: WorkflowData<CreateOrderPaymentCollectionWorkflowInput>) => {
|
||||||
const order = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "order",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
throw_if_key_not_found: true,
|
}).config({ name: "get-order" })
|
||||||
list: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
const paymentCollectionData = transform(
|
const paymentCollectionData = transform(
|
||||||
{ order, input },
|
{ order, input },
|
||||||
|
|||||||
@@ -8,17 +8,21 @@ import {
|
|||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
ProductVariantDTO,
|
ProductVariantDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import { FulfillmentWorkflowEvents, MathBN, Modules } from "@medusajs/framework/utils"
|
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
FulfillmentWorkflowEvents,
|
||||||
WorkflowResponse,
|
MathBN,
|
||||||
|
Modules,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
import {
|
||||||
createHook,
|
createHook,
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||||
import { createShipmentWorkflow } from "../../fulfillment"
|
import { createShipmentWorkflow } from "../../fulfillment"
|
||||||
import { registerOrderShipmentStep } from "../steps"
|
import { registerOrderShipmentStep } from "../steps"
|
||||||
import {
|
import {
|
||||||
@@ -198,8 +202,9 @@ export const createOrderShipmentWorkflowId = "create-order-shipment"
|
|||||||
export const createOrderShipmentWorkflow = createWorkflow(
|
export const createOrderShipmentWorkflow = createWorkflow(
|
||||||
createOrderShipmentWorkflowId,
|
createOrderShipmentWorkflowId,
|
||||||
(input: WorkflowData<CreateOrderShipmentWorkflowInput>) => {
|
(input: WorkflowData<CreateOrderShipmentWorkflowInput>) => {
|
||||||
const order: OrderDTO = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "orders",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"status",
|
"status",
|
||||||
@@ -216,10 +221,8 @@ export const createOrderShipmentWorkflow = createWorkflow(
|
|||||||
"fulfillments.items.line_item_id",
|
"fulfillments.items.line_item_id",
|
||||||
"fulfillments.items.inventory_item_id",
|
"fulfillments.items.inventory_item_id",
|
||||||
],
|
],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
}).config({ name: "get-order" })
|
||||||
throw_if_key_not_found: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
createShipmentValidateOrder({ order, input })
|
createShipmentValidateOrder({ order, input })
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import {
|
|||||||
PaymentCollectionStatus,
|
PaymentCollectionStatus,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
|
WorkflowData,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { removeRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
import { removeRemoteLinkStep, useQueryGraphStep } from "../../common"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This step validates that the order doesn't have an active payment collection.
|
* This step validates that the order doesn't have an active payment collection.
|
||||||
@@ -62,12 +62,11 @@ export const deleteOrderPaymentCollections = createWorkflow(
|
|||||||
(
|
(
|
||||||
input: WorkflowData<DeleteOrderPaymentCollectionsInput>
|
input: WorkflowData<DeleteOrderPaymentCollectionsInput>
|
||||||
): WorkflowData<void> => {
|
): WorkflowData<void> => {
|
||||||
const paymentCollection = useRemoteQueryStep({
|
const { data: paymentCollection } = useQueryGraphStep({
|
||||||
entry_point: "payment_collection",
|
entity: "payment_collection",
|
||||||
|
filters: { id: input.id },
|
||||||
fields: ["id", "status"],
|
fields: ["id", "status"],
|
||||||
variables: { id: input.id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
throw_if_key_not_found: true,
|
|
||||||
list: false,
|
|
||||||
}).config({ name: "payment-collection-query" })
|
}).config({ name: "payment-collection-query" })
|
||||||
|
|
||||||
throwUnlessStatusIsNotPaid({ paymentCollection })
|
throwUnlessStatusIsNotPaid({ paymentCollection })
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import {
|
|||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowResponse,
|
|
||||||
createHook,
|
createHook,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
when,
|
when,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumber, ShippingOptionPriceType } from "@medusajs/framework/utils"
|
import { BigNumber, ShippingOptionPriceType } from "@medusajs/framework/utils"
|
||||||
import { calculateShippingOptionsPricesStep } from "../../fulfillment/steps"
|
import { calculateShippingOptionsPricesStep } from "../../fulfillment/steps"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep, useRemoteQueryStep } from "../../common"
|
||||||
import { pricingContextResult } from "../../cart/utils/schemas"
|
import { pricingContextResult } from "../../cart/utils/schemas"
|
||||||
|
|
||||||
const COMMON_OPTIONS_FIELDS = [
|
const COMMON_OPTIONS_FIELDS = [
|
||||||
@@ -167,11 +167,11 @@ export const fetchShippingOptionsForOrderWorkflowId = "fetch-shipping-option"
|
|||||||
export const fetchShippingOptionForOrderWorkflow = createWorkflow(
|
export const fetchShippingOptionForOrderWorkflow = createWorkflow(
|
||||||
fetchShippingOptionsForOrderWorkflowId,
|
fetchShippingOptionsForOrderWorkflowId,
|
||||||
function (input: FetchShippingOptionForOrderWorkflowInput) {
|
function (input: FetchShippingOptionForOrderWorkflowInput) {
|
||||||
const initialOption = useRemoteQueryStep({
|
const { data: initialOption } = useQueryGraphStep({
|
||||||
entry_point: "shipping_option",
|
entity: "shipping_option",
|
||||||
variables: { id: input.shipping_option_id },
|
filters: { id: input.shipping_option_id },
|
||||||
fields: ["id", "price_type"],
|
fields: ["id", "price_type"],
|
||||||
list: false,
|
options: { isList: false },
|
||||||
}).config({ name: "shipping-option-query" })
|
}).config({ name: "shipping-option-query" })
|
||||||
|
|
||||||
const isCalculatedPriceShippingOption = transform(
|
const isCalculatedPriceShippingOption = transform(
|
||||||
@@ -184,19 +184,18 @@ export const fetchShippingOptionForOrderWorkflow = createWorkflow(
|
|||||||
{ isCalculatedPriceShippingOption },
|
{ isCalculatedPriceShippingOption },
|
||||||
({ isCalculatedPriceShippingOption }) => isCalculatedPriceShippingOption
|
({ isCalculatedPriceShippingOption }) => isCalculatedPriceShippingOption
|
||||||
).then(() => {
|
).then(() => {
|
||||||
const order = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "orders",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: ["id", "shipping_address", "items.*", "items.variant.*"],
|
fields: ["id", "shipping_address", "items.*", "items.variant.*"],
|
||||||
variables: { id: input.order_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
list: false,
|
|
||||||
throw_if_key_not_found: true,
|
|
||||||
}).config({ name: "order-query" })
|
}).config({ name: "order-query" })
|
||||||
|
|
||||||
const shippingOption = useRemoteQueryStep({
|
const { data: shippingOption } = useQueryGraphStep({
|
||||||
entry_point: "shipping_option",
|
entity: "shipping_option",
|
||||||
|
filters: { id: input.shipping_option_id },
|
||||||
fields: [...COMMON_OPTIONS_FIELDS],
|
fields: [...COMMON_OPTIONS_FIELDS],
|
||||||
variables: { id: input.shipping_option_id },
|
options: { isList: false },
|
||||||
list: false,
|
|
||||||
}).config({ name: "calculated-option" })
|
}).config({ name: "calculated-option" })
|
||||||
|
|
||||||
const calculateShippingOptionsPricesData = transform(
|
const calculateShippingOptionsPricesData = transform(
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import type { OrderDTO, OrderDetailDTO } from "@medusajs/framework/types"
|
import type { OrderDetailDTO } from "@medusajs/framework/types"
|
||||||
import { deduplicate } from "@medusajs/framework/utils"
|
import { deduplicate } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
getLastFulfillmentStatus,
|
getLastFulfillmentStatus,
|
||||||
getLastPaymentStatus,
|
getLastPaymentStatus,
|
||||||
@@ -88,13 +88,12 @@ export const getOrderDetailWorkflow = createWorkflow(
|
|||||||
return { ...input.filters, id: input.order_id, version: input.version }
|
return { ...input.filters, id: input.order_id, version: input.version }
|
||||||
})
|
})
|
||||||
|
|
||||||
const order: OrderDTO = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "orders",
|
entity: "order",
|
||||||
fields,
|
filters: variables,
|
||||||
variables,
|
fields: fields,
|
||||||
list: false,
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
throw_if_key_not_found: true,
|
}).config({ name: "get-order" })
|
||||||
})
|
|
||||||
|
|
||||||
const aggregatedOrder = transform({ order }, ({ order }) => {
|
const aggregatedOrder = transform({ order }, ({ order }) => {
|
||||||
const order_ = order as OrderDetailDTO
|
const order_ = order as OrderDetailDTO
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { OrderDTO, OrderDetailDTO } from "@medusajs/framework/types"
|
import type { OrderDetailDTO, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { deduplicate } from "@medusajs/framework/utils"
|
import { deduplicate } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
import type { ListShippingOptionsForOrderWorkflowInput } from "@medusajs/framework/types"
|
import type { ListShippingOptionsForOrderWorkflowInput } from "@medusajs/framework/types"
|
||||||
|
|
||||||
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
||||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
|
||||||
|
|
||||||
export const listShippingOptionsForOrderWorkflowId =
|
export const listShippingOptionsForOrderWorkflowId =
|
||||||
"list-shipping-options-for-order"
|
"list-shipping-options-for-order"
|
||||||
@@ -125,8 +124,9 @@ export const listShippingOptionsForOrderWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const shippingOptions = useRemoteQueryStep({
|
const { data: shippingOptions } = useQueryGraphStep({
|
||||||
entry_point: "shipping_options",
|
entity: "shipping_option",
|
||||||
|
filters: queryVariables.filters,
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"name",
|
||||||
@@ -153,7 +153,6 @@ export const listShippingOptionsForOrderWorkflow = createWorkflow(
|
|||||||
"rules.value",
|
"rules.value",
|
||||||
"rules.operator",
|
"rules.operator",
|
||||||
],
|
],
|
||||||
variables: queryVariables,
|
|
||||||
}).config({ name: "shipping-options-query" })
|
}).config({ name: "shipping-options-query" })
|
||||||
|
|
||||||
const shippingOptionsWithInventory = transform(
|
const shippingOptionsWithInventory = transform(
|
||||||
|
|||||||
+14
-15
@@ -14,14 +14,14 @@ import {
|
|||||||
Modules,
|
Modules,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||||
import { markFulfillmentAsDeliveredWorkflow } from "../../fulfillment"
|
import { markFulfillmentAsDeliveredWorkflow } from "../../fulfillment"
|
||||||
import { registerOrderDeliveryStep } from "../steps/register-delivery"
|
import { registerOrderDeliveryStep } from "../steps/register-delivery"
|
||||||
import {
|
import {
|
||||||
@@ -221,16 +221,17 @@ export const markOrderFulfillmentAsDeliveredWorkflow = createWorkflow(
|
|||||||
markOrderFulfillmentAsDeliveredWorkflowId,
|
markOrderFulfillmentAsDeliveredWorkflowId,
|
||||||
(input: WorkflowData<MarkOrderFulfillmentAsDeliveredWorkflowInput>) => {
|
(input: WorkflowData<MarkOrderFulfillmentAsDeliveredWorkflowInput>) => {
|
||||||
const { fulfillmentId, orderId } = input
|
const { fulfillmentId, orderId } = input
|
||||||
const fulfillment = useRemoteQueryStep({
|
|
||||||
entry_point: "fulfillment",
|
|
||||||
fields: ["id"],
|
|
||||||
variables: { id: fulfillmentId },
|
|
||||||
throw_if_key_not_found: true,
|
|
||||||
list: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
const order = useRemoteQueryStep({
|
const { data: fulfillment } = useQueryGraphStep({
|
||||||
entry_point: "order",
|
entity: "fulfillment",
|
||||||
|
filters: { id: fulfillmentId },
|
||||||
|
fields: ["id"],
|
||||||
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
|
}).config({ name: "get-fulfillment" })
|
||||||
|
|
||||||
|
const { data: order } = useQueryGraphStep({
|
||||||
|
entity: "order",
|
||||||
|
filters: { id: orderId },
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"summary",
|
"summary",
|
||||||
@@ -248,9 +249,7 @@ export const markOrderFulfillmentAsDeliveredWorkflow = createWorkflow(
|
|||||||
"items.variant.inventory_items.inventory.id",
|
"items.variant.inventory_items.inventory.id",
|
||||||
"items.variant.inventory_items.required_quantity",
|
"items.variant.inventory_items.required_quantity",
|
||||||
],
|
],
|
||||||
variables: { id: orderId },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
throw_if_key_not_found: true,
|
|
||||||
list: false,
|
|
||||||
}).config({ name: "order-query" })
|
}).config({ name: "order-query" })
|
||||||
|
|
||||||
orderFulfillmentDeliverablilityValidationStep({ order, fulfillment })
|
orderFulfillmentDeliverablilityValidationStep({ order, fulfillment })
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import type { PaymentCollectionDTO } from "@medusajs/framework/types"
|
import type { PaymentCollectionDTO } from "@medusajs/framework/types"
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { MedusaError } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
authorizePaymentSessionStep,
|
authorizePaymentSessionStep,
|
||||||
capturePaymentWorkflow,
|
capturePaymentWorkflow,
|
||||||
@@ -97,13 +97,12 @@ export const markPaymentCollectionAsPaidId = "mark-payment-collection-as-paid"
|
|||||||
export const markPaymentCollectionAsPaid = createWorkflow(
|
export const markPaymentCollectionAsPaid = createWorkflow(
|
||||||
markPaymentCollectionAsPaidId,
|
markPaymentCollectionAsPaidId,
|
||||||
(input: WorkflowData<MarkPaymentCollectionAsPaidInput>) => {
|
(input: WorkflowData<MarkPaymentCollectionAsPaidInput>) => {
|
||||||
const paymentCollection = useRemoteQueryStep({
|
const { data: paymentCollection } = useQueryGraphStep({
|
||||||
entry_point: "payment_collection",
|
entity: "payment_collection",
|
||||||
|
filters: { id: input.payment_collection_id },
|
||||||
fields: ["id", "status", "amount"],
|
fields: ["id", "status", "amount"],
|
||||||
variables: { id: input.payment_collection_id },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
throw_if_key_not_found: true,
|
}).config({ name: "get-payment-collection" })
|
||||||
list: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
throwUnlessPaymentCollectionNotPaid({ paymentCollection })
|
throwUnlessPaymentCollectionNotPaid({ paymentCollection })
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { OrderWorkflowDTO } from "@medusajs/framework/types"
|
import type { OrderWorkflowDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
when,
|
when,
|
||||||
|
WorkflowData,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import { getItemTaxLinesStep } from "../../tax/steps/get-item-tax-lines"
|
import { getItemTaxLinesStep } from "../../tax/steps/get-item-tax-lines"
|
||||||
import { setOrderTaxLinesForItemsStep } from "../steps"
|
import { setOrderTaxLinesForItemsStep } from "../steps"
|
||||||
|
|
||||||
@@ -190,31 +190,35 @@ export const updateOrderTaxLinesWorkflow = createWorkflow(
|
|||||||
return isFullOrder ? completeOrderFields : orderFields
|
return isFullOrder ? completeOrderFields : orderFields
|
||||||
})
|
})
|
||||||
|
|
||||||
const order = useRemoteQueryStep({
|
const { data: order } = useQueryGraphStep({
|
||||||
entry_point: "order",
|
entity: "order",
|
||||||
|
filters: { id: input.order_id },
|
||||||
fields: fetchOrderFields,
|
fields: fetchOrderFields,
|
||||||
variables: { id: input.order_id },
|
options: { isList: false },
|
||||||
list: false,
|
}).config({ name: "order-query" })
|
||||||
})
|
|
||||||
|
|
||||||
const items = when({ input }, ({ input }) => {
|
const items = when({ input }, ({ input }) => {
|
||||||
return input.item_ids!?.length > 0
|
return input.item_ids!?.length > 0
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return useRemoteQueryStep({
|
const { data: orderLineItems } = useQueryGraphStep({
|
||||||
entry_point: "order_line_item",
|
entity: "order_line_item",
|
||||||
|
filters: { id: input.item_ids },
|
||||||
fields: lineItemFields,
|
fields: lineItemFields,
|
||||||
variables: { id: input.item_ids },
|
|
||||||
}).config({ name: "query-order-line-items" })
|
}).config({ name: "query-order-line-items" })
|
||||||
|
|
||||||
|
return orderLineItems
|
||||||
})
|
})
|
||||||
|
|
||||||
const shippingMethods = when({ input }, ({ input }) => {
|
const shippingMethods = when({ input }, ({ input }) => {
|
||||||
return input.shipping_method_ids!?.length > 0
|
return input.shipping_method_ids!?.length > 0
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return useRemoteQueryStep({
|
const { data: orderShippingMethods } = useQueryGraphStep({
|
||||||
entry_point: "order_shipping_method",
|
entity: "order_shipping_method",
|
||||||
|
filters: { id: input.shipping_method_ids },
|
||||||
fields: shippingMethodFields,
|
fields: shippingMethodFields,
|
||||||
variables: { id: input.shipping_method_ids },
|
|
||||||
}).config({ name: "query-order-shipping-methods" })
|
}).config({ name: "query-order-shipping-methods" })
|
||||||
|
|
||||||
|
return orderShippingMethods
|
||||||
})
|
})
|
||||||
|
|
||||||
const taxLineItems = getItemTaxLinesStep(
|
const taxLineItems = getItemTaxLinesStep(
|
||||||
|
|||||||
Reference in new issue
Block a user