feat: Returns order previews (#8135)
* work on order previews * fix create return shipping flow * fix http tests * fix tests
This commit is contained in:
@@ -185,8 +185,18 @@ medusaIntegrationTestRunner({
|
|||||||
display_id: 1,
|
display_id: 1,
|
||||||
order_version: 2,
|
order_version: 2,
|
||||||
status: "requested",
|
status: "requested",
|
||||||
items: [],
|
})
|
||||||
shipping_methods: [],
|
)
|
||||||
|
|
||||||
|
expect(result.data.order_preview).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
return_id: returnId,
|
||||||
|
change_type: "return",
|
||||||
|
actions: [],
|
||||||
|
description: "Test",
|
||||||
|
status: "pending",
|
||||||
|
order_id: order.id,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -205,15 +215,21 @@ medusaIntegrationTestRunner({
|
|||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(result.data.return).toEqual(
|
expect(result.data.order_preview).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: order.id,
|
||||||
order_id: order.id,
|
items: expect.arrayContaining([
|
||||||
display_id: 1,
|
expect.objectContaining({
|
||||||
order_version: 2,
|
id: expect.any(String),
|
||||||
status: "requested",
|
title: "Custom Item 2",
|
||||||
items: [],
|
unit_price: 50,
|
||||||
shipping_methods: [],
|
quantity: 1,
|
||||||
|
subtotal: 50,
|
||||||
|
total: 50,
|
||||||
|
fulfilled_total: 50,
|
||||||
|
return_requested_total: 50,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -225,11 +241,30 @@ medusaIntegrationTestRunner({
|
|||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(result.data.order.shipping_methods[1]).toEqual(
|
expect(result.data.order_preview).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 1000,
|
id: order.id,
|
||||||
name: "Return shipping",
|
items: expect.arrayContaining([
|
||||||
shipping_option_id: returnShippingOption.id,
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
title: "Custom Item 2",
|
||||||
|
unit_price: 50,
|
||||||
|
quantity: 1,
|
||||||
|
subtotal: 50,
|
||||||
|
total: 50,
|
||||||
|
fulfilled_total: 50,
|
||||||
|
return_requested_total: 50,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
shipping_methods: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "Return shipping",
|
||||||
|
amount: 1000,
|
||||||
|
subtotal: 1000,
|
||||||
|
total: 1000,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -239,27 +274,30 @@ medusaIntegrationTestRunner({
|
|||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(result.data.return).toEqual(
|
expect(result.data.order_preview).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: order.id,
|
||||||
order_id: order.id,
|
items: expect.arrayContaining([
|
||||||
display_id: 1,
|
|
||||||
order_version: 2,
|
|
||||||
status: "requested",
|
|
||||||
items: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
title: "Custom Item 2",
|
||||||
|
unit_price: 50,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
item_id: item.id,
|
subtotal: 50,
|
||||||
received_quantity: 0,
|
total: 50,
|
||||||
|
fulfilled_total: 50,
|
||||||
|
return_requested_total: 50,
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
shipping_methods: [
|
shipping_methods: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 1000,
|
id: expect.any(String),
|
||||||
name: "Return shipping",
|
name: "Return shipping",
|
||||||
shipping_option_id: returnShippingOption.id,
|
amount: 1000,
|
||||||
|
subtotal: 1000,
|
||||||
|
total: 1000,
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:integration": "jest --no-cache --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
|
"test:integration": "jest --no-cache --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
|
||||||
"test:integration:chunk": "jest --silent --no-cache --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
|
"test:integration:chunk": "jest --silent --no-cache --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
|
||||||
"build": "tsc ./src/* --allowJs --outDir ./dist"
|
"build": "tsc ./src/* --allowJs --outDir ./dist"
|
||||||
},
|
},
|
||||||
|
|||||||
+10
-2
@@ -70,7 +70,11 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(orderChangePreview.shipping_methods[1].actions).toEqual([
|
const shippingMethod = orderChangePreview.shipping_methods?.find(
|
||||||
|
(sm) => sm.shipping_option_id === shippingOptionId
|
||||||
|
)
|
||||||
|
|
||||||
|
expect((shippingMethod as any).actions).toEqual([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
reference: "order_shipping_method",
|
reference: "order_shipping_method",
|
||||||
@@ -95,7 +99,11 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(orderChangePreview.shipping_methods[1].actions).toEqual([
|
const shippingMethod = orderChangePreview.shipping_methods?.find(
|
||||||
|
(sm) => sm.shipping_option_id === shippingOptionId
|
||||||
|
)
|
||||||
|
|
||||||
|
expect((shippingMethod as any).actions).toEqual([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
reference: "order_shipping_method",
|
reference: "order_shipping_method",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
beginReturnOrderWorkflow,
|
beginReturnOrderWorkflow,
|
||||||
|
createOrderFulfillmentWorkflow,
|
||||||
requestItemReturnWorkflow,
|
requestItemReturnWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { IOrderModuleService, OrderDTO, ReturnDTO } from "@medusajs/types"
|
import { IOrderModuleService, OrderDTO, ReturnDTO } from "@medusajs/types"
|
||||||
@@ -37,6 +38,18 @@ medusaIntegrationTestRunner({
|
|||||||
inventoryItem: fixtures.inventoryItem,
|
inventoryItem: fixtures.inventoryItem,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await createOrderFulfillmentWorkflow(container).run({
|
||||||
|
input: {
|
||||||
|
order_id: order.id,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
quantity: 1,
|
||||||
|
id: order.items![0].id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
await beginReturnOrderWorkflow(container).run({
|
await beginReturnOrderWorkflow(container).run({
|
||||||
input: { order_id: order.id },
|
input: { order_id: order.id },
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
@@ -59,9 +72,7 @@ medusaIntegrationTestRunner({
|
|||||||
describe("requestItemReturnWorkflow", () => {
|
describe("requestItemReturnWorkflow", () => {
|
||||||
it("should successfully add a return item to order change", async () => {
|
it("should successfully add a return item to order change", async () => {
|
||||||
const item = order.items![0]
|
const item = order.items![0]
|
||||||
const {
|
const { result } = await requestItemReturnWorkflow(container).run({
|
||||||
result: [returnItem],
|
|
||||||
} = await requestItemReturnWorkflow(container).run({
|
|
||||||
input: {
|
input: {
|
||||||
return_id: returnOrder.id,
|
return_id: returnOrder.id,
|
||||||
items: [
|
items: [
|
||||||
@@ -74,19 +85,18 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const returnItem = result.items?.[0]
|
||||||
|
|
||||||
expect(returnItem).toEqual(
|
expect(returnItem).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
order_id: order.id,
|
title: "Custom Item 2",
|
||||||
return_id: returnOrder.id,
|
unit_price: 50,
|
||||||
reference: "return",
|
quantity: 1,
|
||||||
reference_id: returnOrder.id,
|
subtotal: 50,
|
||||||
details: {
|
total: 50,
|
||||||
reference_id: item.id,
|
fulfilled_total: 50,
|
||||||
quantity: 1,
|
return_requested_total: 50,
|
||||||
},
|
|
||||||
internal_note: "test",
|
|
||||||
action: "RETURN_ITEM",
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -142,7 +152,7 @@ medusaIntegrationTestRunner({
|
|||||||
const item = order.items![0]
|
const item = order.items![0]
|
||||||
|
|
||||||
const [orderChange] = await service.listOrderChanges(
|
const [orderChange] = await service.listOrderChanges(
|
||||||
{ order_id: order.id },
|
{ order_id: order.id, return_id: returnOrder.id },
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -173,7 +183,7 @@ medusaIntegrationTestRunner({
|
|||||||
const item = order.items![0]
|
const item = order.items![0]
|
||||||
|
|
||||||
const [orderChange] = await service.listOrderChanges(
|
const [orderChange] = await service.listOrderChanges(
|
||||||
{ order_id: order.id },
|
{ order_id: order.id, return_id: returnOrder.id },
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:integration": "jest --silent --no-cache --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
|
"test:integration": "jest --silent=false --no-cache --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
|
||||||
"test:integration:chunk": "jest --silent --no-cache --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
|
"test:integration:chunk": "jest --silent --no-cache --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
|
||||||
"build": "tsc ./src/* --allowJs --outDir ./dist"
|
"build": "tsc ./src/* --allowJs --outDir ./dist"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
|
import { previewOrderChangeStep } from "../steps"
|
||||||
import { confirmOrderChanges } from "../steps/confirm-order-changes"
|
import { confirmOrderChanges } from "../steps/confirm-order-changes"
|
||||||
import { createReturnItems } from "../steps/create-return-items"
|
import { createReturnItems } from "../steps/create-return-items"
|
||||||
import {
|
import {
|
||||||
@@ -38,7 +39,7 @@ const validationStep = createStep(
|
|||||||
export const confirmReturnRequestWorkflowId = "confirm-return-request"
|
export const confirmReturnRequestWorkflowId = "confirm-return-request"
|
||||||
export const confirmReturnRequestWorkflow = createWorkflow(
|
export const confirmReturnRequestWorkflow = createWorkflow(
|
||||||
confirmReturnRequestWorkflowId,
|
confirmReturnRequestWorkflowId,
|
||||||
function (input: WorkflowInput): WorkflowData<void> {
|
function (input: WorkflowInput): WorkflowData<OrderDTO> {
|
||||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||||
entry_point: "return",
|
entry_point: "return",
|
||||||
fields: ["id", "status", "order_id"],
|
fields: ["id", "status", "order_id"],
|
||||||
@@ -86,5 +87,7 @@ export const confirmReturnRequestWorkflow = createWorkflow(
|
|||||||
createReturnItems({ returnId: orderReturn.id, changes: returnItemActions })
|
createReturnItems({ returnId: orderReturn.id, changes: returnItemActions })
|
||||||
|
|
||||||
confirmOrderChanges({ changes: [orderChange], orderId: order.id })
|
confirmOrderChanges({ changes: [orderChange], orderId: order.id })
|
||||||
|
|
||||||
|
return previewOrderChangeStep(order.id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
|
import { previewOrderChangeStep } from "../steps"
|
||||||
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
||||||
import { createOrderShippingMethods } from "../steps/create-order-shipping-methods"
|
import { createOrderShippingMethods } from "../steps/create-order-shipping-methods"
|
||||||
import { previewOrderChangeStep } from "../steps/preview-order-change"
|
|
||||||
import {
|
import {
|
||||||
throwIfIsCancelled,
|
throwIfIsCancelled,
|
||||||
throwIfOrderChangeIsNotActive,
|
throwIfOrderChangeIsNotActive,
|
||||||
@@ -45,7 +45,7 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
|||||||
return_id: string
|
return_id: string
|
||||||
shipping_option_id: string
|
shipping_option_id: string
|
||||||
custom_price?: BigNumberInput
|
custom_price?: BigNumberInput
|
||||||
}): WorkflowData {
|
}): WorkflowData<OrderDTO> {
|
||||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||||
entry_point: "return",
|
entry_point: "return",
|
||||||
fields: ["id", "status", "order_id"],
|
fields: ["id", "status", "order_id"],
|
||||||
@@ -93,14 +93,19 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
|||||||
validationStep({ order, orderReturn, orderChange })
|
validationStep({ order, orderReturn, orderChange })
|
||||||
|
|
||||||
const shippingMethodInput = transform(
|
const shippingMethodInput = transform(
|
||||||
{ orderReturn, shippingOptions, orderChange },
|
{
|
||||||
|
orderReturn,
|
||||||
|
shippingOptions,
|
||||||
|
customPrice: input.custom_price,
|
||||||
|
orderChange,
|
||||||
|
},
|
||||||
(data) => {
|
(data) => {
|
||||||
const option = data.shippingOptions[0]
|
const option = data.shippingOptions[0]
|
||||||
const orderChange = data.orderChange
|
const orderChange = data.orderChange
|
||||||
|
|
||||||
return {
|
return {
|
||||||
shipping_option_id: option.id,
|
shipping_option_id: option.id,
|
||||||
amount: option.calculated_price.calculated_amount,
|
amount: data.customPrice ?? option.calculated_price.calculated_amount,
|
||||||
is_tax_inclusive:
|
is_tax_inclusive:
|
||||||
!!option.calculated_price.is_calculated_price_tax_inclusive,
|
!!option.calculated_price.is_calculated_price_tax_inclusive,
|
||||||
data: option.data ?? {},
|
data: option.data ?? {},
|
||||||
@@ -141,8 +146,8 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
|||||||
return {
|
return {
|
||||||
action: ChangeActionType.SHIPPING_ADD,
|
action: ChangeActionType.SHIPPING_ADD,
|
||||||
reference: "order_shipping_method",
|
reference: "order_shipping_method",
|
||||||
reference_id: createdMethod.id,
|
|
||||||
order_change_id: orderChange.id,
|
order_change_id: orderChange.id,
|
||||||
|
reference_id: createdMethod.id,
|
||||||
amount: methodPrice,
|
amount: methodPrice,
|
||||||
order_id: order.id,
|
order_id: order.id,
|
||||||
return_id: orderReturn.id,
|
return_id: orderReturn.id,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
OrderChangeActionDTO,
|
|
||||||
OrderChangeDTO,
|
OrderChangeDTO,
|
||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
@@ -13,6 +12,7 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
|
import { previewOrderChangeStep } from "../steps"
|
||||||
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
||||||
import {
|
import {
|
||||||
throwIfIsCancelled,
|
throwIfIsCancelled,
|
||||||
@@ -45,7 +45,7 @@ export const requestItemReturnWorkflow = createWorkflow(
|
|||||||
requestItemReturnWorkflowId,
|
requestItemReturnWorkflowId,
|
||||||
function (
|
function (
|
||||||
input: WorkflowData<OrderWorkflow.RequestItemReturnWorkflowInput>
|
input: WorkflowData<OrderWorkflow.RequestItemReturnWorkflowInput>
|
||||||
): WorkflowData<OrderChangeActionDTO[]> {
|
): WorkflowData<OrderDTO> {
|
||||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||||
entry_point: "return",
|
entry_point: "return",
|
||||||
fields: ["id", "status", "order_id"],
|
fields: ["id", "status", "order_id"],
|
||||||
@@ -94,6 +94,8 @@ export const requestItemReturnWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return createOrderChangeActionsStep(orderChangeActionInput)
|
createOrderChangeActionsStep(orderChangeActionInput)
|
||||||
|
|
||||||
|
return previewOrderChangeStep(order.id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const POST = async (
|
|||||||
|
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
await requestItemReturnWorkflow(req.scope).run({
|
const { result } = await requestItemReturnWorkflow(req.scope).run({
|
||||||
input: { ...req.validatedBody, return_id: id },
|
input: { ...req.validatedBody, return_id: id },
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ export const POST = async (
|
|||||||
const [orderReturn] = await remoteQuery(queryObject)
|
const [orderReturn] = await remoteQuery(queryObject)
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
order_preview: result,
|
||||||
return: orderReturn,
|
return: orderReturn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ export const POST = async (
|
|||||||
|
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
await confirmReturnRequestWorkflow(req.scope).run({
|
const { result } = await confirmReturnRequestWorkflow(req.scope).run({
|
||||||
input: { return_id: id },
|
input: { return_id: id },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log("RESULT: ", result)
|
||||||
|
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
entryPoint: "return",
|
entryPoint: "return",
|
||||||
variables: {
|
variables: {
|
||||||
@@ -35,6 +37,7 @@ export const POST = async (
|
|||||||
const [orderReturn] = await remoteQuery(queryObject)
|
const [orderReturn] = await remoteQuery(queryObject)
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
order_preview: result,
|
||||||
return: orderReturn,
|
return: orderReturn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { createReturnShippingMethodWorkflow } from "@medusajs/core-flows"
|
import { createReturnShippingMethodWorkflow } from "@medusajs/core-flows"
|
||||||
|
import {
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
remoteQueryObjectFromString,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -11,13 +15,27 @@ export const POST = async (
|
|||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const { result: orderPreview } = await createReturnShippingMethodWorkflow(
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
req.scope
|
|
||||||
).run({
|
const { result } = await createReturnShippingMethodWorkflow(req.scope).run({
|
||||||
input: { ...req.validatedBody, return_id: id },
|
input: { ...req.validatedBody, return_id: id },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
entryPoint: "return",
|
||||||
|
variables: {
|
||||||
|
id,
|
||||||
|
filters: {
|
||||||
|
...req.filterableFields,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fields: req.remoteQueryConfig.fields,
|
||||||
|
})
|
||||||
|
|
||||||
|
const [orderReturn] = await remoteQuery(queryObject)
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
order: orderPreview,
|
order_preview: result,
|
||||||
|
return: orderReturn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ export const defaultAdminReturnFields = [
|
|||||||
"refund_amount",
|
"refund_amount",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"*items",
|
|
||||||
"*shipping_methods",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export const retrieveTransformQueryConfig = {
|
export const retrieveTransformQueryConfig = {
|
||||||
|
|||||||
@@ -61,5 +61,8 @@ export const POST = async (
|
|||||||
|
|
||||||
const [orderReturn] = await remoteQuery(queryObject)
|
const [orderReturn] = await remoteQuery(queryObject)
|
||||||
|
|
||||||
res.status(200).json({ return: orderReturn })
|
res.json({
|
||||||
|
order_preview: result,
|
||||||
|
return: orderReturn,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user