feat(order): cancel fulfillment (#7573)
This commit is contained in:
+16
-2
@@ -1,3 +1,4 @@
|
||||
import { cancelOrderFulfillmentWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -6,16 +7,29 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminOrderCancelFulfillmentType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<AdminOrderCancelFulfillmentType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const variables = { id: req.params.id }
|
||||
|
||||
// TODO: Workflow to cancel fulfillment + adjust inventory
|
||||
const input = {
|
||||
...req.validatedBody,
|
||||
order_id: req.params.id,
|
||||
}
|
||||
|
||||
const { errors } = await cancelOrderFulfillmentWorkflow(req.scope).run({
|
||||
input,
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
if (Array.isArray(errors) && errors[0]) {
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order",
|
||||
|
||||
@@ -79,3 +79,12 @@ export const AdminOrderCreateShipment = z.object({
|
||||
export type AdminOrderCreateShipmentType = z.infer<
|
||||
typeof AdminOrderCreateShipment
|
||||
>
|
||||
|
||||
export const AdminOrderCancelFulfillment = z.object({
|
||||
fulfillment_id: z.string(),
|
||||
no_notification: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export type AdminOrderCancelFulfillmentType = z.infer<
|
||||
typeof AdminOrderCancelFulfillment
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user