feat: update return request (#8302)
This commit is contained in:
@@ -46,6 +46,8 @@ export * from "./return/remove-return-shipping-method"
|
||||
export * from "./return/request-item-return"
|
||||
export * from "./return/update-receive-item-return-request"
|
||||
export * from "./return/update-request-item-return"
|
||||
export * from "./return/update-return"
|
||||
export * from "./return/update-return-shipping-method"
|
||||
export * from "./update-order-change-actions"
|
||||
export * from "./update-tax-lines"
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { OrderChangeDTO, OrderWorkflow, ReturnDTO } from "@medusajs/types"
|
||||
import { OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../../common"
|
||||
import { updateReturnsStep } from "../../steps"
|
||||
import { previewOrderChangeStep } from "../../steps/preview-order-change"
|
||||
import {
|
||||
throwIfIsCancelled,
|
||||
throwIfOrderChangeIsNotActive,
|
||||
} from "../../utils/order-validation"
|
||||
|
||||
const validationStep = createStep(
|
||||
"validate-update-return",
|
||||
async function ({
|
||||
orderChange,
|
||||
orderReturn,
|
||||
}: {
|
||||
orderReturn: ReturnDTO
|
||||
orderChange: OrderChangeDTO
|
||||
}) {
|
||||
throwIfIsCancelled(orderReturn, "Return")
|
||||
throwIfOrderChangeIsNotActive({ orderChange })
|
||||
}
|
||||
)
|
||||
|
||||
export const updateReturnWorkflowId = "update-return"
|
||||
export const updateReturnWorkflow = createWorkflow(
|
||||
updateReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.UpdateReturnWorkflowInput>
|
||||
): WorkflowData {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
variables: { id: input.return_id },
|
||||
list: false,
|
||||
throw_if_key_not_found: true,
|
||||
})
|
||||
|
||||
const orderChange: OrderChangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_change",
|
||||
fields: ["id", "status", "version", "actions.*"],
|
||||
variables: {
|
||||
filters: {
|
||||
order_id: orderReturn.order_id,
|
||||
return_id: orderReturn.id,
|
||||
status: [OrderChangeStatus.PENDING, OrderChangeStatus.REQUESTED],
|
||||
},
|
||||
},
|
||||
list: false,
|
||||
}).config({ name: "order-change-query" })
|
||||
|
||||
validationStep({ orderReturn, orderChange })
|
||||
|
||||
const updateData = transform({ input }, ({ input }) => {
|
||||
return {
|
||||
id: input.return_id,
|
||||
location_id: input.location_id,
|
||||
no_notification: input.no_notification,
|
||||
metadata: input.metadata,
|
||||
}
|
||||
})
|
||||
|
||||
updateReturnsStep([updateData])
|
||||
|
||||
return previewOrderChangeStep(orderReturn.order_id)
|
||||
}
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FindParams, HttpTypes, SelectParams } from "@medusajs/types"
|
||||
import { HttpTypes, SelectParams } from "@medusajs/types"
|
||||
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
@@ -178,4 +178,21 @@ export class Return {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async updateRequest(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateReturnRequest,
|
||||
query?: HttpTypes.SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminReturnResponse>(
|
||||
`/admin/returns/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,12 @@ export interface AdminConfirmReturnRequest {
|
||||
no_notification?: boolean
|
||||
}
|
||||
|
||||
export interface AdminUpdateReturnRequest {
|
||||
location_id?: string
|
||||
no_notification?: boolean
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface AdminReturnFilters extends FindParams {
|
||||
id?: string[] | string | OperatorMap<string | string[]>
|
||||
order_id?: string[] | string | OperatorMap<string | string[]>
|
||||
|
||||
@@ -13,3 +13,5 @@ export * from "./items"
|
||||
export * from "./receive-return"
|
||||
export * from "./request-item-return"
|
||||
export * from "./shipping-method"
|
||||
export * from "./update-return"
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface UpdateReturnWorkflowInput {
|
||||
return_id: string
|
||||
location_id?: string
|
||||
no_notification?: boolean
|
||||
metadata?: Record<string, any> | null
|
||||
}
|
||||
Reference in New Issue
Block a user