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:
5
.changeset/little-falcons-count.md
Normal file
5
.changeset/little-falcons-count.md
Normal file
@@ -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 { confirmVariantInventoryWorkflow } from "../../cart/workflows/confirm-variant-inventory"
|
||||
import { getVariantsAndItemsWithPrices } from "../../cart/workflows/get-variants-and-items-with-prices"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { createOrderLineItemsStep } from "../steps"
|
||||
import { productVariantsFields } from "../utils/fields"
|
||||
|
||||
@@ -98,8 +98,9 @@ export const addOrderLineItemsWorkflow = createWorkflow(
|
||||
OrderWorkflow.OrderAddLineItemWorkflowInput & AdditionalData
|
||||
>
|
||||
) => {
|
||||
const order = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: [
|
||||
"id",
|
||||
"sales_channel_id",
|
||||
@@ -108,9 +109,7 @@ export const addOrderLineItemsWorkflow = createWorkflow(
|
||||
"email",
|
||||
"currency_code",
|
||||
],
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "order-query" })
|
||||
|
||||
const variantIds = transform({ input }, (data) => {
|
||||
|
||||
@@ -16,15 +16,19 @@ import {
|
||||
OrderWorkflowEvents,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createHook,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
emitEventStep,
|
||||
useQueryGraphStep,
|
||||
useRemoteQueryStep,
|
||||
} from "../../common"
|
||||
import { cancelFulfillmentWorkflow } from "../../fulfillment"
|
||||
import { adjustInventoryLevelsStep } from "../../inventory"
|
||||
import { cancelOrderFulfillmentStep } from "../steps/cancel-fulfillment"
|
||||
@@ -32,8 +36,10 @@ import {
|
||||
throwIfItemsDoesNotExistsInOrder,
|
||||
throwIfOrderIsCancelled,
|
||||
} from "../utils/order-validation"
|
||||
import { createReservationsStep } from "../../reservation"
|
||||
import { updateReservationsStep } from "../../reservation"
|
||||
import {
|
||||
createReservationsStep,
|
||||
updateReservationsStep,
|
||||
} from "../../reservation"
|
||||
|
||||
type OrderItemWithVariantDTO = OrderLineItemDTO & {
|
||||
variant?: ProductVariantDTO & {
|
||||
@@ -307,9 +313,9 @@ export const cancelOrderFulfillmentWorkflowId = "cancel-order-fulfillment"
|
||||
export const cancelOrderFulfillmentWorkflow = createWorkflow(
|
||||
cancelOrderFulfillmentWorkflowId,
|
||||
(input: WorkflowData<CancelOrderFulfillmentWorkflowInput>) => {
|
||||
const order: OrderDTO & { fulfillments: FulfillmentDTO[] } =
|
||||
useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: [
|
||||
"id",
|
||||
"status",
|
||||
@@ -328,10 +334,8 @@ export const cancelOrderFulfillmentWorkflow = createWorkflow(
|
||||
"fulfillments.items.line_item_id",
|
||||
"fulfillments.items.inventory_item_id",
|
||||
],
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
cancelOrderFulfillmentValidateOrder({ order, input })
|
||||
|
||||
|
||||
@@ -5,21 +5,21 @@ import {
|
||||
PaymentCollectionDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
deepFlatMap,
|
||||
MathBN,
|
||||
MedusaError,
|
||||
OrderWorkflowEvents,
|
||||
PaymentCollectionStatus,
|
||||
deepFlatMap,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createHook,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
when,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||
import { updatePaymentCollectionStep } from "../../payment-collection"
|
||||
@@ -68,9 +68,7 @@ export type CancelValidateOrderStepInput = {
|
||||
*/
|
||||
export const cancelValidateOrder = createStep(
|
||||
"cancel-validate-order",
|
||||
({
|
||||
order,
|
||||
}: CancelValidateOrderStepInput) => {
|
||||
({ order }: CancelValidateOrderStepInput) => {
|
||||
const order_ = order as OrderDTO & {
|
||||
payment_collections: PaymentCollectionDTO[]
|
||||
fulfillments: FulfillmentDTO[]
|
||||
@@ -128,7 +126,7 @@ export const cancelOrderWorkflow = createWorkflow(
|
||||
cancelOrderWorkflowId,
|
||||
(input: WorkflowData<OrderWorkflow.CancelOrderWorkflowInput>) => {
|
||||
const orderQuery = useQueryGraphStep({
|
||||
entity: "orders",
|
||||
entity: "order",
|
||||
fields: [
|
||||
"id",
|
||||
"status",
|
||||
@@ -143,7 +141,7 @@ export const cancelOrderWorkflow = createWorkflow(
|
||||
],
|
||||
filters: { id: input.order_id },
|
||||
options: { throwIfKeyNotFound: true },
|
||||
}).config({ name: "get-cart" })
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
const order = transform(
|
||||
{ orderQuery },
|
||||
|
||||
@@ -18,17 +18,18 @@ import {
|
||||
OrderWorkflowEvents,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createHook,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
createRemoteLinkStep,
|
||||
emitEventStep,
|
||||
useQueryGraphStep,
|
||||
useRemoteQueryStep,
|
||||
} from "../../common"
|
||||
import { createFulfillmentWorkflow } from "../../fulfillment"
|
||||
@@ -393,8 +394,9 @@ export const createOrderFulfillmentWorkflowId = "create-order-fulfillment"
|
||||
export const createOrderFulfillmentWorkflow = createWorkflow(
|
||||
createOrderFulfillmentWorkflowId,
|
||||
(input: WorkflowData<CreateOrderFulfillmentWorkflowInput>) => {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: [
|
||||
"id",
|
||||
"display_id",
|
||||
@@ -444,10 +446,8 @@ export const createOrderFulfillmentWorkflow = createWorkflow(
|
||||
"shipping_methods.data",
|
||||
"shipping_methods.amount",
|
||||
],
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
createFulfillmentValidateOrder({ order, inputItems: input.items })
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { updatePaymentCollectionStep } from "../../payment-collection"
|
||||
import { cancelPaymentCollectionWorkflow } from "../../payment-collection/workflows/cancel-payment-collection"
|
||||
import { createOrderPaymentCollectionWorkflow } from "./create-order-payment-collection"
|
||||
@@ -63,18 +63,17 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
||||
amount?: number
|
||||
}>
|
||||
) => {
|
||||
const order = useRemoteQueryStep({
|
||||
entry_point: "order",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
||||
variables: { id: input.order_id },
|
||||
throw_if_key_not_found: true,
|
||||
list: false,
|
||||
filters: { id: input.order_id },
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
})
|
||||
|
||||
const orderPaymentCollections = useRemoteQueryStep({
|
||||
entry_point: "order_payment_collection",
|
||||
const { data: orderPaymentCollections } = useQueryGraphStep({
|
||||
entity: "order_payment_collection",
|
||||
fields: ["payment_collection_id"],
|
||||
variables: { order_id: order.id },
|
||||
filters: { order_id: order.id },
|
||||
}).config({ name: "order-payment-collection-query" })
|
||||
|
||||
const orderPaymentCollectionIds = transform(
|
||||
@@ -83,10 +82,9 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
||||
orderPaymentCollections.map((opc) => opc.payment_collection_id)
|
||||
)
|
||||
|
||||
const existingPaymentCollection = useRemoteQueryStep({
|
||||
entry_point: "payment_collection",
|
||||
const { data: existingPaymentCollection } = useQueryGraphStep({
|
||||
entity: "payment_collection",
|
||||
fields: ["id", "status"],
|
||||
variables: {
|
||||
filters: {
|
||||
id: orderPaymentCollectionIds,
|
||||
status: [
|
||||
@@ -98,8 +96,7 @@ export const createOrUpdateOrderPaymentCollectionWorkflow = createWorkflow(
|
||||
PaymentCollectionStatus.PARTIALLY_AUTHORIZED,
|
||||
],
|
||||
},
|
||||
},
|
||||
list: false,
|
||||
options: { isList: false },
|
||||
}).config({ name: "payment-collection-query" })
|
||||
|
||||
const shouldRecreate = transform(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { createPaymentCollectionsStep } from "../../cart"
|
||||
import { createRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
||||
import { createRemoteLinkStep, useQueryGraphStep } from "../../common"
|
||||
|
||||
/**
|
||||
* The details of the payment collection to create.
|
||||
@@ -47,13 +47,12 @@ export const createOrderPaymentCollectionWorkflowId =
|
||||
export const createOrderPaymentCollectionWorkflow = createWorkflow(
|
||||
createOrderPaymentCollectionWorkflowId,
|
||||
(input: WorkflowData<CreateOrderPaymentCollectionWorkflowInput>) => {
|
||||
const order = useRemoteQueryStep({
|
||||
entry_point: "order",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: ["id", "summary", "total", "currency_code", "region_id"],
|
||||
variables: { id: input.order_id },
|
||||
throw_if_key_not_found: true,
|
||||
list: false,
|
||||
})
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
const paymentCollectionData = transform(
|
||||
{ order, input },
|
||||
|
||||
@@ -8,17 +8,21 @@ import {
|
||||
OrderWorkflow,
|
||||
ProductVariantDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import { FulfillmentWorkflowEvents, MathBN, Modules } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
FulfillmentWorkflowEvents,
|
||||
MathBN,
|
||||
Modules,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
createHook,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||
import { createShipmentWorkflow } from "../../fulfillment"
|
||||
import { registerOrderShipmentStep } from "../steps"
|
||||
import {
|
||||
@@ -198,8 +202,9 @@ export const createOrderShipmentWorkflowId = "create-order-shipment"
|
||||
export const createOrderShipmentWorkflow = createWorkflow(
|
||||
createOrderShipmentWorkflowId,
|
||||
(input: WorkflowData<CreateOrderShipmentWorkflowInput>) => {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: [
|
||||
"id",
|
||||
"status",
|
||||
@@ -216,10 +221,8 @@ export const createOrderShipmentWorkflow = createWorkflow(
|
||||
"fulfillments.items.line_item_id",
|
||||
"fulfillments.items.inventory_item_id",
|
||||
],
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
createShipmentValidateOrder({ order, input })
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import {
|
||||
PaymentCollectionStatus,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
WorkflowData,
|
||||
} 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.
|
||||
@@ -62,12 +62,11 @@ export const deleteOrderPaymentCollections = createWorkflow(
|
||||
(
|
||||
input: WorkflowData<DeleteOrderPaymentCollectionsInput>
|
||||
): WorkflowData<void> => {
|
||||
const paymentCollection = useRemoteQueryStep({
|
||||
entry_point: "payment_collection",
|
||||
const { data: paymentCollection } = useQueryGraphStep({
|
||||
entity: "payment_collection",
|
||||
filters: { id: input.id },
|
||||
fields: ["id", "status"],
|
||||
variables: { id: input.id },
|
||||
throw_if_key_not_found: true,
|
||||
list: false,
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "payment-collection-query" })
|
||||
|
||||
throwUnlessStatusIsNotPaid({ paymentCollection })
|
||||
|
||||
@@ -6,15 +6,15 @@ import {
|
||||
ShippingOptionDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowResponse,
|
||||
createHook,
|
||||
createWorkflow,
|
||||
transform,
|
||||
when,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { BigNumber, ShippingOptionPriceType } from "@medusajs/framework/utils"
|
||||
import { calculateShippingOptionsPricesStep } from "../../fulfillment/steps"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep, useRemoteQueryStep } from "../../common"
|
||||
import { pricingContextResult } from "../../cart/utils/schemas"
|
||||
|
||||
const COMMON_OPTIONS_FIELDS = [
|
||||
@@ -167,11 +167,11 @@ export const fetchShippingOptionsForOrderWorkflowId = "fetch-shipping-option"
|
||||
export const fetchShippingOptionForOrderWorkflow = createWorkflow(
|
||||
fetchShippingOptionsForOrderWorkflowId,
|
||||
function (input: FetchShippingOptionForOrderWorkflowInput) {
|
||||
const initialOption = useRemoteQueryStep({
|
||||
entry_point: "shipping_option",
|
||||
variables: { id: input.shipping_option_id },
|
||||
const { data: initialOption } = useQueryGraphStep({
|
||||
entity: "shipping_option",
|
||||
filters: { id: input.shipping_option_id },
|
||||
fields: ["id", "price_type"],
|
||||
list: false,
|
||||
options: { isList: false },
|
||||
}).config({ name: "shipping-option-query" })
|
||||
|
||||
const isCalculatedPriceShippingOption = transform(
|
||||
@@ -184,19 +184,18 @@ export const fetchShippingOptionForOrderWorkflow = createWorkflow(
|
||||
{ isCalculatedPriceShippingOption },
|
||||
({ isCalculatedPriceShippingOption }) => isCalculatedPriceShippingOption
|
||||
).then(() => {
|
||||
const order = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: ["id", "shipping_address", "items.*", "items.variant.*"],
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "order-query" })
|
||||
|
||||
const shippingOption = useRemoteQueryStep({
|
||||
entry_point: "shipping_option",
|
||||
const { data: shippingOption } = useQueryGraphStep({
|
||||
entity: "shipping_option",
|
||||
filters: { id: input.shipping_option_id },
|
||||
fields: [...COMMON_OPTIONS_FIELDS],
|
||||
variables: { id: input.shipping_option_id },
|
||||
list: false,
|
||||
options: { isList: false },
|
||||
}).config({ name: "calculated-option" })
|
||||
|
||||
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 {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import {
|
||||
getLastFulfillmentStatus,
|
||||
getLastPaymentStatus,
|
||||
@@ -88,13 +88,12 @@ export const getOrderDetailWorkflow = createWorkflow(
|
||||
return { ...input.filters, id: input.order_id, version: input.version }
|
||||
})
|
||||
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields,
|
||||
variables,
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: variables,
|
||||
fields: fields,
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-order" })
|
||||
|
||||
const aggregatedOrder = transform({ order }, ({ order }) => {
|
||||
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 {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
import type { ListShippingOptionsForOrderWorkflowInput } from "@medusajs/framework/types"
|
||||
|
||||
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
||||
|
||||
export const listShippingOptionsForOrderWorkflowId =
|
||||
"list-shipping-options-for-order"
|
||||
@@ -125,8 +124,9 @@ export const listShippingOptionsForOrderWorkflow = createWorkflow(
|
||||
}
|
||||
)
|
||||
|
||||
const shippingOptions = useRemoteQueryStep({
|
||||
entry_point: "shipping_options",
|
||||
const { data: shippingOptions } = useQueryGraphStep({
|
||||
entity: "shipping_option",
|
||||
filters: queryVariables.filters,
|
||||
fields: [
|
||||
"id",
|
||||
"name",
|
||||
@@ -153,7 +153,6 @@ export const listShippingOptionsForOrderWorkflow = createWorkflow(
|
||||
"rules.value",
|
||||
"rules.operator",
|
||||
],
|
||||
variables: queryVariables,
|
||||
}).config({ name: "shipping-options-query" })
|
||||
|
||||
const shippingOptionsWithInventory = transform(
|
||||
|
||||
@@ -14,14 +14,14 @@ import {
|
||||
Modules,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||
import { markFulfillmentAsDeliveredWorkflow } from "../../fulfillment"
|
||||
import { registerOrderDeliveryStep } from "../steps/register-delivery"
|
||||
import {
|
||||
@@ -221,16 +221,17 @@ export const markOrderFulfillmentAsDeliveredWorkflow = createWorkflow(
|
||||
markOrderFulfillmentAsDeliveredWorkflowId,
|
||||
(input: WorkflowData<MarkOrderFulfillmentAsDeliveredWorkflowInput>) => {
|
||||
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({
|
||||
entry_point: "order",
|
||||
const { data: fulfillment } = useQueryGraphStep({
|
||||
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: [
|
||||
"id",
|
||||
"summary",
|
||||
@@ -248,9 +249,7 @@ export const markOrderFulfillmentAsDeliveredWorkflow = createWorkflow(
|
||||
"items.variant.inventory_items.inventory.id",
|
||||
"items.variant.inventory_items.required_quantity",
|
||||
],
|
||||
variables: { id: orderId },
|
||||
throw_if_key_not_found: true,
|
||||
list: false,
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "order-query" })
|
||||
|
||||
orderFulfillmentDeliverablilityValidationStep({ order, fulfillment })
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { PaymentCollectionDTO } from "@medusajs/framework/types"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import {
|
||||
authorizePaymentSessionStep,
|
||||
capturePaymentWorkflow,
|
||||
@@ -97,13 +97,12 @@ export const markPaymentCollectionAsPaidId = "mark-payment-collection-as-paid"
|
||||
export const markPaymentCollectionAsPaid = createWorkflow(
|
||||
markPaymentCollectionAsPaidId,
|
||||
(input: WorkflowData<MarkPaymentCollectionAsPaidInput>) => {
|
||||
const paymentCollection = useRemoteQueryStep({
|
||||
entry_point: "payment_collection",
|
||||
const { data: paymentCollection } = useQueryGraphStep({
|
||||
entity: "payment_collection",
|
||||
filters: { id: input.payment_collection_id },
|
||||
fields: ["id", "status", "amount"],
|
||||
variables: { id: input.payment_collection_id },
|
||||
throw_if_key_not_found: true,
|
||||
list: false,
|
||||
})
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-payment-collection" })
|
||||
|
||||
throwUnlessPaymentCollectionNotPaid({ paymentCollection })
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { OrderWorkflowDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
transform,
|
||||
when,
|
||||
WorkflowData,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { getItemTaxLinesStep } from "../../tax/steps/get-item-tax-lines"
|
||||
import { setOrderTaxLinesForItemsStep } from "../steps"
|
||||
|
||||
@@ -190,31 +190,35 @@ export const updateOrderTaxLinesWorkflow = createWorkflow(
|
||||
return isFullOrder ? completeOrderFields : orderFields
|
||||
})
|
||||
|
||||
const order = useRemoteQueryStep({
|
||||
entry_point: "order",
|
||||
const { data: order } = useQueryGraphStep({
|
||||
entity: "order",
|
||||
filters: { id: input.order_id },
|
||||
fields: fetchOrderFields,
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
})
|
||||
options: { isList: false },
|
||||
}).config({ name: "order-query" })
|
||||
|
||||
const items = when({ input }, ({ input }) => {
|
||||
return input.item_ids!?.length > 0
|
||||
}).then(() => {
|
||||
return useRemoteQueryStep({
|
||||
entry_point: "order_line_item",
|
||||
const { data: orderLineItems } = useQueryGraphStep({
|
||||
entity: "order_line_item",
|
||||
filters: { id: input.item_ids },
|
||||
fields: lineItemFields,
|
||||
variables: { id: input.item_ids },
|
||||
}).config({ name: "query-order-line-items" })
|
||||
|
||||
return orderLineItems
|
||||
})
|
||||
|
||||
const shippingMethods = when({ input }, ({ input }) => {
|
||||
return input.shipping_method_ids!?.length > 0
|
||||
}).then(() => {
|
||||
return useRemoteQueryStep({
|
||||
entry_point: "order_shipping_method",
|
||||
const { data: orderShippingMethods } = useQueryGraphStep({
|
||||
entity: "order_shipping_method",
|
||||
filters: { id: input.shipping_method_ids },
|
||||
fields: shippingMethodFields,
|
||||
variables: { id: input.shipping_method_ids },
|
||||
}).config({ name: "query-order-shipping-methods" })
|
||||
|
||||
return orderShippingMethods
|
||||
})
|
||||
|
||||
const taxLineItems = getItemTaxLinesStep(
|
||||
|
||||
Reference in New Issue
Block a user