feat(core-flow): order edit endpoints (#8596)
* The relevant part of this PR is only at folder `packages/medusa/src/api/admin/order-edits/` All the other changes are Types Missing: * `/store` endpoints to confirm/decline the order change * http tests of the full flow
This commit is contained in:
committed by
GitHub
parent
b23ddcdde8
commit
c92aa3e397
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -49,7 +50,7 @@ export const orderClaimAddNewItemWorkflow = createWorkflow(
|
||||
orderClaimAddNewItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderClaimAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -48,7 +49,7 @@ export const orderClaimItemWorkflow = createWorkflow(
|
||||
orderClaimItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderClaimItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -60,7 +61,7 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
|
||||
orderClaimRequestItemReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderClaimRequestItemReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "order_id", "return_id", "canceled_at"],
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ChangeActionType,
|
||||
@@ -183,7 +184,7 @@ export const confirmClaimRequestWorkflow = createWorkflow(
|
||||
confirmClaimRequestWorkflowId,
|
||||
function (
|
||||
input: ConfirmClaimRequestWorkflowInput
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
@@ -52,7 +53,7 @@ export const createClaimShippingMethodWorkflow = createWorkflow(
|
||||
claim_id?: string
|
||||
shipping_option_id: string
|
||||
custom_price?: BigNumberInput
|
||||
}): WorkflowResponse<OrderDTO> {
|
||||
}): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -64,7 +65,7 @@ export const removeAddItemClaimActionWorkflow = createWorkflow(
|
||||
removeAddItemClaimActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteOrderClaimItemActionWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -94,7 +95,12 @@ export const removeAddItemClaimActionWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeClaimAddItemActionValidationStep({ order, input, orderClaim, orderChange })
|
||||
removeClaimAddItemActionValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderClaim,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
deleteOrderChangeActionsStep({ ids: [input.action_id] })
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -64,7 +65,7 @@ export const removeItemClaimActionWorkflow = createWorkflow(
|
||||
removeItemClaimActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteOrderClaimItemActionWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -94,7 +95,12 @@ export const removeItemClaimActionWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeClaimItemActionValidationStep({ order, input, orderClaim, orderChange })
|
||||
removeClaimItemActionValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderClaim,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
deleteOrderChangeActionsStep({ ids: [input.action_id] })
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -65,7 +65,7 @@ export const removeClaimShippingMethodWorkflow = createWorkflow(
|
||||
removeClaimShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteClaimShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -68,7 +69,7 @@ export const updateClaimAddItemWorkflow = createWorkflow(
|
||||
updateClaimAddItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateClaimAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -68,7 +69,7 @@ export const updateClaimItemWorkflow = createWorkflow(
|
||||
updateClaimItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateClaimItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderClaimDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -67,7 +67,7 @@ export const updateClaimShippingMethodWorkflow = createWorkflow(
|
||||
updateClaimShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateClaimShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, Modules, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
@@ -173,7 +174,9 @@ export const confirmExchangeRequestWorkflowId = "confirm-exchange-request"
|
||||
*/
|
||||
export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
confirmExchangeRequestWorkflowId,
|
||||
function (input: ConfirmExchangeRequestWorkflowInput): WorkflowResponse<OrderDTO> {
|
||||
function (
|
||||
input: ConfirmExchangeRequestWorkflowInput
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
@@ -52,7 +53,7 @@ export const createExchangeShippingMethodWorkflow = createWorkflow(
|
||||
exchange_id?: string
|
||||
shipping_option_id: string
|
||||
custom_price?: BigNumberInput
|
||||
}): WorkflowResponse<OrderDTO> {
|
||||
}): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -49,7 +50,7 @@ export const orderExchangeAddNewItemWorkflow = createWorkflow(
|
||||
orderExchangeAddNewItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderExchangeAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -60,7 +61,7 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
|
||||
orderExchangeRequestItemReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderExchangeRequestItemReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "order_id", "return_id", "canceled_at"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -64,7 +65,7 @@ export const removeItemExchangeActionWorkflow = createWorkflow(
|
||||
removeItemExchangeActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteOrderExchangeItemActionWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -94,7 +95,12 @@ export const removeItemExchangeActionWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeExchangeItemActionValidationStep({ order, input, orderExchange, orderChange })
|
||||
removeExchangeItemActionValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderExchange,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
deleteOrderChangeActionsStep({ ids: [input.action_id] })
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -65,7 +65,7 @@ export const removeExchangeShippingMethodWorkflow = createWorkflow(
|
||||
removeExchangeShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteExchangeShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -87,7 +87,11 @@ export const removeExchangeShippingMethodWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeExchangeShippingMethodValidationStep({ orderExchange, orderChange, input })
|
||||
removeExchangeShippingMethodValidationStep({
|
||||
orderExchange,
|
||||
orderChange,
|
||||
input,
|
||||
})
|
||||
|
||||
const dataToRemove = transform(
|
||||
{ orderChange, input },
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -68,7 +69,7 @@ export const updateExchangeAddItemWorkflow = createWorkflow(
|
||||
updateExchangeAddItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateExchangeAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -98,7 +99,12 @@ export const updateExchangeAddItemWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
updateExchangeAddItemValidationStep({ order, input, orderExchange, orderChange })
|
||||
updateExchangeAddItemValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderExchange,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
const updateData = transform(
|
||||
{ orderChange, input },
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -67,7 +67,7 @@ export const updateExchangeShippingMethodWorkflow = createWorkflow(
|
||||
updateExchangeShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateExchangeShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderExchange: OrderExchangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_exchange",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -39,6 +39,15 @@ export * from "./exchange/update-exchange-add-item"
|
||||
export * from "./exchange/update-exchange-shipping-method"
|
||||
export * from "./get-order-detail"
|
||||
export * from "./get-orders-list"
|
||||
export * from "./order-edit/begin-order-edit"
|
||||
export * from "./order-edit/cancel-begin-order-edit"
|
||||
export * from "./order-edit/confirm-order-edit-request"
|
||||
export * from "./order-edit/create-order-edit-shipping-method"
|
||||
export * from "./order-edit/order-edit-add-new-item"
|
||||
export * from "./order-edit/remove-order-edit-item-action"
|
||||
export * from "./order-edit/remove-order-edit-shipping-method"
|
||||
export * from "./order-edit/update-order-edit-add-item"
|
||||
export * from "./order-edit/update-order-edit-shipping-method"
|
||||
export * from "./return/begin-receive-return"
|
||||
export * from "./return/begin-return"
|
||||
export * from "./return/cancel-receive-return"
|
||||
|
||||
@@ -13,7 +13,7 @@ import { throwIfOrderIsCancelled } from "../../utils/order-validation"
|
||||
/**
|
||||
* This step validates that an order-edit can be requested for an order.
|
||||
*/
|
||||
export const beginOrderOrderEditValidationStep = createStep(
|
||||
export const beginorderEditValidationStep = createStep(
|
||||
"begin-order-edit-validation",
|
||||
async function ({ order }: { order: OrderDTO }) {
|
||||
throwIfOrderIsCancelled({ order })
|
||||
@@ -27,7 +27,7 @@ export const beginOrderEditOrderWorkflowId = "begin-order-edit-order"
|
||||
export const beginOrderEditOrderWorkflow = createWorkflow(
|
||||
beginOrderEditOrderWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.BeginOrderOrderEditWorkflowInput>
|
||||
input: WorkflowData<OrderWorkflow.BeginorderEditWorkflowInput>
|
||||
): WorkflowResponse<OrderChangeDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
@@ -37,7 +37,7 @@ export const beginOrderEditOrderWorkflow = createWorkflow(
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
|
||||
beginOrderOrderEditValidationStep({ order })
|
||||
beginorderEditValidationStep({ order })
|
||||
|
||||
const orderChangeInput = transform({ input }, ({ input }) => {
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
||||
import { OrderChangeDTO, OrderDTO, OrderPreviewDTO } from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowResponse,
|
||||
@@ -45,7 +45,7 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
||||
confirmOrderEditRequestWorkflowId,
|
||||
function (
|
||||
input: ConfirmOrderEditRequestWorkflowInput
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields: [
|
||||
@@ -117,7 +117,7 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
||||
variables: { id: input.order_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
}).config({ name: "order-query" })
|
||||
}).config({ name: "order-items-query" })
|
||||
|
||||
const { variants, items } = transform({ orderItems }, ({ orderItems }) => {
|
||||
const allItems: any[] = []
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { BigNumberInput, OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
||||
import {
|
||||
BigNumberInput,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowResponse,
|
||||
@@ -43,7 +48,7 @@ export const createOrderEditShippingMethodWorkflow = createWorkflow(
|
||||
order_id: string
|
||||
shipping_option_id: string
|
||||
custom_price?: BigNumberInput
|
||||
}): WorkflowResponse<OrderDTO> {
|
||||
}): WorkflowResponse<OrderPreviewDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields: ["id", "status", "currency_code", "canceled_at"],
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { OrderChangeDTO, OrderDTO, OrderWorkflow } from "@medusajs/types"
|
||||
import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
@@ -33,15 +38,15 @@ export const orderEditAddNewItemValidationStep = createStep(
|
||||
}
|
||||
)
|
||||
|
||||
export const orderOrderEditAddNewItemWorkflowId = "order-edit-add-new-item"
|
||||
export const orderEditAddNewItemWorkflowId = "order-edit-add-new-item"
|
||||
/**
|
||||
* This workflow adds new items to an order edit.
|
||||
*/
|
||||
export const orderOrderEditAddNewItemWorkflow = createWorkflow(
|
||||
orderOrderEditAddNewItemWorkflowId,
|
||||
export const orderEditAddNewItemWorkflow = createWorkflow(
|
||||
orderEditAddNewItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.OrderEditAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields: ["id", "status", "canceled_at", "items.*"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -61,7 +62,7 @@ export const removeItemOrderEditActionWorkflow = createWorkflow(
|
||||
removeItemOrderEditActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteOrderEditItemActionWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields: ["id", "status", "canceled_at", "items.*"],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -58,7 +58,7 @@ export const removeOrderEditShippingMethodWorkflow = createWorkflow(
|
||||
removeOrderEditShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteOrderEditShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderChange: OrderChangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_change",
|
||||
fields: ["id", "status", "version", "actions.*"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -64,7 +65,7 @@ export const updateOrderEditAddItemWorkflow = createWorkflow(
|
||||
updateOrderEditAddItemWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateOrderEditAddNewItemWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const order: OrderDTO = useRemoteQueryStep({
|
||||
entry_point: "orders",
|
||||
fields: ["id", "status", "canceled_at", "items.*"],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -60,7 +60,7 @@ export const updateOrderEditShippingMethodWorkflow = createWorkflow(
|
||||
updateOrderEditShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateOrderEditShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderChange: OrderChangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_change",
|
||||
fields: ["id", "status", "version", "actions.*"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderReturnItemDTO,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -134,7 +135,9 @@ export const confirmReturnReceiveWorkflowId = "confirm-return-receive"
|
||||
*/
|
||||
export const confirmReturnReceiveWorkflow = createWorkflow(
|
||||
confirmReturnReceiveWorkflowId,
|
||||
function (input: ConfirmReceiveReturnRequestWorkflowInput): WorkflowResponse<OrderDTO> {
|
||||
function (
|
||||
input: ConfirmReceiveReturnRequestWorkflowInput
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: [
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
FulfillmentWorkflow,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
@@ -137,7 +138,9 @@ export const confirmReturnRequestWorkflowId = "confirm-return-request"
|
||||
*/
|
||||
export const confirmReturnRequestWorkflow = createWorkflow(
|
||||
confirmReturnRequestWorkflowId,
|
||||
function (input: ConfirmReturnRequestWorkflowInput): WorkflowResponse<OrderDTO> {
|
||||
function (
|
||||
input: ConfirmReturnRequestWorkflowInput
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "location_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
BigNumberInput,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
@@ -53,7 +54,7 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
||||
exchange_id?: string
|
||||
shipping_option_id: string
|
||||
custom_price?: BigNumberInput
|
||||
}): WorkflowResponse<OrderDTO> {
|
||||
}): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -55,7 +56,7 @@ export const dismissItemReturnRequestWorkflow = createWorkflow(
|
||||
dismissItemReturnRequestWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.ReceiveOrderReturnItemsWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at", "items.*"],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -55,7 +56,7 @@ export const receiveItemReturnRequestWorkflow = createWorkflow(
|
||||
receiveItemReturnRequestWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.ReceiveOrderReturnItemsWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at", "items.*"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -72,7 +73,7 @@ export const removeItemReceiveReturnActionWorkflow = createWorkflow(
|
||||
removeItemReceiveReturnActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteRequestItemReceiveReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -102,7 +103,12 @@ export const removeItemReceiveReturnActionWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeItemReceiveReturnActionValidationStep({ order, input, orderReturn, orderChange })
|
||||
removeItemReceiveReturnActionValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderReturn,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
deleteOrderChangeActionsStep({ ids: [input.action_id] })
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -66,7 +67,7 @@ export const removeItemReturnActionWorkflow = createWorkflow(
|
||||
removeItemReturnActionWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteRequestItemReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -106,7 +107,12 @@ export const removeItemReturnActionWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeReturnItemActionValidationStep({ order, input, orderReturn, orderChange })
|
||||
removeReturnItemActionValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderReturn,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
deleteOrderChangeActionsStep({ ids: [input.action_id] })
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -65,7 +65,7 @@ export const removeReturnShippingMethodWorkflow = createWorkflow(
|
||||
removeReturnShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.DeleteReturnShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -87,7 +87,11 @@ export const removeReturnShippingMethodWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
removeReturnShippingMethodValidationStep({ orderReturn, orderChange, input })
|
||||
removeReturnShippingMethodValidationStep({
|
||||
orderReturn,
|
||||
orderChange,
|
||||
input,
|
||||
})
|
||||
|
||||
const dataToRemove = transform(
|
||||
{ orderChange, input },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -61,7 +62,7 @@ export const requestItemReturnWorkflow = createWorkflow(
|
||||
requestItemReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.RequestItemReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -76,7 +77,7 @@ export const updateReceiveItemReturnRequestWorkflow = createWorkflow(
|
||||
updateReceiveItemReturnRequestWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateReceiveItemReturnRequestWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -106,7 +107,12 @@ export const updateReceiveItemReturnRequestWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
updateReceiveItemReturnRequestValidationStep({ order, input, orderReturn, orderChange })
|
||||
updateReceiveItemReturnRequestValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderReturn,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
const updateData = transform(
|
||||
{ orderChange, input },
|
||||
|
||||
@@ -2,16 +2,17 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, isDefined, OrderChangeStatus } from "@medusajs/utils"
|
||||
import { ChangeActionType, OrderChangeStatus, isDefined } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../../common"
|
||||
import {
|
||||
@@ -81,7 +82,7 @@ export const updateRequestItemReturnWorkflow = createWorkflow(
|
||||
updateRequestItemReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateRequestItemReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -111,7 +112,12 @@ export const updateRequestItemReturnWorkflow = createWorkflow(
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
updateRequestItemReturnValidationStep({ order, input, orderReturn, orderChange })
|
||||
updateRequestItemReturnValidationStep({
|
||||
order,
|
||||
input,
|
||||
orderReturn,
|
||||
orderChange,
|
||||
})
|
||||
|
||||
const updateData = transform(
|
||||
{ orderChange, input },
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -67,7 +67,7 @@ export const updateReturnShippingMethodWorkflow = createWorkflow(
|
||||
updateReturnShippingMethodWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateReturnShippingMethodWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -45,7 +45,7 @@ export const updateReturnWorkflow = createWorkflow(
|
||||
updateReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateReturnWorkflowInput>
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
): WorkflowResponse<OrderPreviewDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OrderDTO } from "../../../order"
|
||||
import { OrderDTO, OrderPreviewDTO } from "../../../order"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminReturn } from "../../return"
|
||||
import { AdminClaim } from "./entities"
|
||||
@@ -18,12 +18,12 @@ export interface AdminClaimOrderResponse {
|
||||
}
|
||||
|
||||
export interface AdminClaimPreviewResponse {
|
||||
order_preview: OrderDTO
|
||||
order_preview: OrderPreviewDTO
|
||||
claim: AdminClaim
|
||||
}
|
||||
|
||||
export interface AdminClaimReturnPreviewResponse {
|
||||
order_preview: OrderDTO
|
||||
order_preview: OrderPreviewDTO
|
||||
return: AdminReturn
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { OrderDTO } from "../../../order";
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { AdminReturn } from "../../return";
|
||||
import { AdminExchange } from "./entities";
|
||||
import { OrderDTO, OrderPreviewDTO } from "../../../order"
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { AdminReturn } from "../../return"
|
||||
import { AdminExchange } from "./entities"
|
||||
|
||||
export interface AdminExchangeResponse {
|
||||
exchange: AdminExchange
|
||||
}
|
||||
|
||||
export type AdminExchangeListResponse = PaginatedResponse<{
|
||||
exchanges: AdminExchange
|
||||
exchanges: AdminExchange
|
||||
}>
|
||||
|
||||
export interface AdminExchangeOrderResponse {
|
||||
@@ -17,15 +17,16 @@ export interface AdminExchangeOrderResponse {
|
||||
}
|
||||
|
||||
export interface AdminExchangePreviewResponse {
|
||||
order_preview: OrderDTO
|
||||
order_preview: OrderPreviewDTO
|
||||
exchange: AdminExchange
|
||||
}
|
||||
|
||||
export interface AdminExchangeRequestResponse extends AdminExchangePreviewResponse {
|
||||
export interface AdminExchangeRequestResponse
|
||||
extends AdminExchangePreviewResponse {
|
||||
return: AdminReturn
|
||||
}
|
||||
|
||||
export interface AdminExchangeReturnResponse {
|
||||
order_preview: OrderDTO
|
||||
order_preview: OrderPreviewDTO
|
||||
return: AdminReturn
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export * from "./inventory-level"
|
||||
export * from "./invite"
|
||||
export * from "./notification"
|
||||
export * from "./order"
|
||||
export * from "./order-edit"
|
||||
export * from "./payment"
|
||||
export * from "./price-list"
|
||||
export * from "./pricing"
|
||||
|
||||
1
packages/core/types/src/http/order-edit/admin/index.ts
Normal file
1
packages/core/types/src/http/order-edit/admin/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,5 @@
|
||||
import { OrderPreviewDTO } from "../../../order"
|
||||
|
||||
export interface AdminOrderEditPreviewResponse {
|
||||
order_preview: OrderPreviewDTO
|
||||
}
|
||||
9
packages/core/types/src/http/order-edit/common.ts
Normal file
9
packages/core/types/src/http/order-edit/common.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface BaseOrderEditItem {
|
||||
id: string
|
||||
order_id: string
|
||||
item_id: string
|
||||
quantity: number
|
||||
metadata?: Record<string, unknown>
|
||||
created_at: string | null
|
||||
updated_at: string | null
|
||||
}
|
||||
2
packages/core/types/src/http/order-edit/index.ts
Normal file
2
packages/core/types/src/http/order-edit/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./admin"
|
||||
export * from "./common"
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface BeginOrderOrderEditWorkflowInput {
|
||||
export interface BeginorderEditWorkflowInput {
|
||||
order_id: string
|
||||
created_by?: string
|
||||
internal_note?: string
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
removeItemExchangeActionWorkflow,
|
||||
updateExchangeAddItemWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -10,11 +11,10 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostExhangesItemsActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { AdminPostExchangesItemsActionReqSchemaType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExhangesItemsActionReqSchemaType>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesItemsActionReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminExchangePreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
@@ -7,11 +7,11 @@ import {
|
||||
AdminGetOrdersParams,
|
||||
AdminPostCancelExchangeReqSchema,
|
||||
AdminPostExchangesAddItemsReqSchema,
|
||||
AdminPostExchangesItemsActionReqSchema,
|
||||
AdminPostExchangesRequestItemsReturnActionReqSchema,
|
||||
AdminPostExchangesReturnRequestItemsReqSchema,
|
||||
AdminPostExchangesShippingActionReqSchema,
|
||||
AdminPostExchangesShippingReqSchema,
|
||||
AdminPostExhangesItemsActionReqSchema,
|
||||
AdminPostOrderExchangesReqSchema,
|
||||
} from "./validators"
|
||||
|
||||
@@ -129,7 +129,7 @@ export const adminExchangeRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
method: ["POST"],
|
||||
matcher: "/admin/exchanges/:id/outbound/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostExhangesItemsActionReqSchema),
|
||||
validateAndTransformBody(AdminPostExchangesItemsActionReqSchema),
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
|
||||
@@ -160,11 +160,11 @@ export type AdminPostExchangesConfirmRequestReqSchemaType = z.infer<
|
||||
typeof AdminPostExchangesConfirmRequestReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostExhangesItemsActionReqSchema = z.object({
|
||||
export const AdminPostExchangesItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostExhangesItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostExhangesItemsActionReqSchema
|
||||
export type AdminPostExchangesItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostExchangesItemsActionReqSchema
|
||||
>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { confirmOrderEditRequestWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const { result } = await confirmOrderEditRequestWorkflow(req.scope).run({
|
||||
input: { order_id: id },
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
removeItemOrderEditActionWorkflow,
|
||||
updateOrderEditAddItemWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostOrderEditsItemsActionReqSchemaType } from "../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsItemsActionReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result } = await updateOrderEditAddItemWorkflow(req.scope).run({
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
order_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeItemOrderEditActionWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
order_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { orderEditAddNewItemWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostOrderEditsAddItemsReqSchemaType } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsAddItemsReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const { result } = await orderEditAddNewItemWorkflow(req.scope).run({
|
||||
input: { ...req.validatedBody, order_id: id },
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
25
packages/medusa/src/api/admin/order-edits/[id]/route.ts
Normal file
25
packages/medusa/src/api/admin/order-edits/[id]/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { cancelBeginOrderEditWorkflow } from "@medusajs/core-flows"
|
||||
import { DeleteResponse } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<DeleteResponse<"order-edit">>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
await cancelBeginOrderEditWorkflow(req.scope).run({
|
||||
input: {
|
||||
order_id: id,
|
||||
},
|
||||
})
|
||||
|
||||
res.status(200).json({
|
||||
id,
|
||||
object: "order-edit",
|
||||
deleted: true,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
removeOrderEditShippingMethodWorkflow,
|
||||
updateOrderEditShippingMethodWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminPostOrderEditsShippingActionReqSchemaType } from "../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsShippingActionReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result } = await updateOrderEditShippingMethodWorkflow(req.scope).run(
|
||||
{
|
||||
input: {
|
||||
data: { ...req.validatedBody },
|
||||
order_id: id,
|
||||
action_id,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const { result: orderPreview } = await removeOrderEditShippingMethodWorkflow(
|
||||
req.scope
|
||||
).run({
|
||||
input: {
|
||||
order_id: id,
|
||||
action_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: orderPreview,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createOrderEditShippingMethodWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostOrderEditsShippingReqSchemaType } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsShippingReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const { result } = await createOrderEditShippingMethodWorkflow(req.scope).run(
|
||||
{
|
||||
input: { ...req.validatedBody, order_id: id },
|
||||
}
|
||||
)
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
71
packages/medusa/src/api/admin/order-edits/middlewares.ts
Normal file
71
packages/medusa/src/api/admin/order-edits/middlewares.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { MiddlewareRoute } from "@medusajs/framework"
|
||||
import { validateAndTransformBody } from "../../utils/validate-body"
|
||||
import {
|
||||
AdminPostOrderEditsAddItemsReqSchema,
|
||||
AdminPostOrderEditsItemsActionReqSchema,
|
||||
AdminPostOrderEditsReqSchema,
|
||||
AdminPostOrderEditsShippingActionReqSchema,
|
||||
AdminPostOrderEditsShippingReqSchema,
|
||||
} from "./validators"
|
||||
|
||||
export const adminOrderEditRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/order-edits/:id",
|
||||
middlewares: [],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits",
|
||||
middlewares: [validateAndTransformBody(AdminPostOrderEditsReqSchema)],
|
||||
},
|
||||
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/items",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderEditsAddItemsReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/items/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderEditsItemsActionReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/order-edits/:id/items/:action_id",
|
||||
middlewares: [],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/shipping-method",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderEditsShippingReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/shipping-method/:action_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderEditsShippingActionReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/order-edits/:id/shipping-method/:action_id",
|
||||
middlewares: [],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/confirm",
|
||||
middlewares: [],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/order-edits/:id",
|
||||
middlewares: [],
|
||||
},
|
||||
]
|
||||
24
packages/medusa/src/api/admin/order-edits/query-config.ts
Normal file
24
packages/medusa/src/api/admin/order-edits/query-config.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export const defaultAdminOrderEditFields = [
|
||||
"id",
|
||||
"order_id",
|
||||
"display_id",
|
||||
"order_version",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"canceled_at",
|
||||
]
|
||||
|
||||
export const defaultAdminDetailsOrderEditFields = [
|
||||
...defaultAdminOrderEditFields,
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsOrderEditFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaults: defaultAdminOrderEditFields,
|
||||
defaultLimit: 20,
|
||||
isList: true,
|
||||
}
|
||||
41
packages/medusa/src/api/admin/order-edits/route.ts
Normal file
41
packages/medusa/src/api/admin/order-edits/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { beginOrderEditOrderWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import { AdminPostOrderEditsReqSchemaType } from "./validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderResponse>
|
||||
) => {
|
||||
const input = req.validatedBody as AdminPostOrderEditsReqSchemaType
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const workflow = beginOrderEditOrderWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
input,
|
||||
})
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order",
|
||||
variables: {
|
||||
id: result.order_id,
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [order] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
order,
|
||||
})
|
||||
}
|
||||
58
packages/medusa/src/api/admin/order-edits/validators.ts
Normal file
58
packages/medusa/src/api/admin/order-edits/validators.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const AdminPostOrderEditsReqSchema = z.object({
|
||||
order_id: z.string(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
export type AdminPostOrderEditsReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderEditsShippingReqSchema = z.object({
|
||||
shipping_option_id: z.string(),
|
||||
custom_price: z.number().optional(),
|
||||
description: z.string().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
|
||||
export type AdminPostOrderEditsShippingReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsShippingReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderEditsShippingActionReqSchema = z.object({
|
||||
custom_price: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
metadata: z.record(z.unknown()).nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostOrderEditsShippingActionReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsShippingActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderEditsAddItemsReqSchema = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
variant_id: z.string(),
|
||||
quantity: z.number(),
|
||||
unit_price: z.number().optional(),
|
||||
internal_note: z.string().optional(),
|
||||
allow_backorder: z.boolean().optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export type AdminPostOrderEditsAddItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsAddItemsReqSchema
|
||||
>
|
||||
export const AdminPostOrderEditsItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostOrderEditsItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsItemsActionReqSchema
|
||||
>
|
||||
@@ -14,6 +14,7 @@ import { adminFulfillmentsRoutesMiddlewares } from "./admin/fulfillments/middlew
|
||||
import { adminInventoryRoutesMiddlewares } from "./admin/inventory-items/middlewares"
|
||||
import { adminInviteRoutesMiddlewares } from "./admin/invites/middlewares"
|
||||
import { adminNotificationRoutesMiddlewares } from "./admin/notifications/middlewares"
|
||||
import { adminOrderEditRoutesMiddlewares } from "./admin/order-edits/middlewares"
|
||||
import { adminOrderRoutesMiddlewares } from "./admin/orders/middlewares"
|
||||
import { adminPaymentRoutesMiddlewares } from "./admin/payments/middlewares"
|
||||
import { adminPriceListsRoutesMiddlewares } from "./admin/price-lists/middlewares"
|
||||
@@ -112,4 +113,5 @@ export default defineMiddlewares([
|
||||
...adminRefundReasonsRoutesMiddlewares,
|
||||
...adminExchangeRoutesMiddlewares,
|
||||
...adminProductVariantRoutesMiddlewares,
|
||||
...adminOrderEditRoutesMiddlewares,
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user