feat(order): cancel fulfillment (#7573)

This commit is contained in:
Carlos R. L. Rodrigues
2024-06-02 09:33:24 -03:00
committed by GitHub
parent 4e04214612
commit af0140d317
30 changed files with 745 additions and 298 deletions
@@ -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
>