chore(core-flows): order update item quantity (#8659)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { orderEditUpdateItemQuantityWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostOrderEditsUpdateItemQuantityReqSchemaType } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsUpdateItemQuantityReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditPreviewResponse>
|
||||
) => {
|
||||
const { id, item_id } = req.params
|
||||
|
||||
const { result } = await orderEditUpdateItemQuantityWorkflow(req.scope).run({
|
||||
input: {
|
||||
...req.validatedBody,
|
||||
order_id: id,
|
||||
items: [
|
||||
{
|
||||
...req.validatedBody,
|
||||
id: item_id,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
res.json({
|
||||
order_preview: result,
|
||||
})
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
AdminPostOrderEditsReqSchema,
|
||||
AdminPostOrderEditsShippingActionReqSchema,
|
||||
AdminPostOrderEditsShippingReqSchema,
|
||||
AdminPostOrderEditsUpdateItemQuantityReqSchema,
|
||||
} from "./validators"
|
||||
|
||||
export const adminOrderEditRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
@@ -34,6 +35,13 @@ export const adminOrderEditRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
validateAndTransformBody(AdminPostOrderEditsItemsActionReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/order-edits/:id/items/item/:item_id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminPostOrderEditsUpdateItemQuantityReqSchema),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["DELETE"],
|
||||
matcher: "/admin/order-edits/:id/items/:action_id",
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { beginOrderEditOrderWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -12,30 +8,16 @@ import { AdminPostOrderEditsReqSchemaType } from "./validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostOrderEditsReqSchemaType>,
|
||||
res: MedusaResponse<HttpTypes.AdminOrderResponse>
|
||||
res: MedusaResponse<HttpTypes.AdminOrderEditResponse>
|
||||
) => {
|
||||
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,
|
||||
order_change: result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ export const AdminPostOrderEditsAddItemsReqSchema = z.object({
|
||||
export type AdminPostOrderEditsAddItemsReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsAddItemsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderEditsItemsActionReqSchema = z.object({
|
||||
quantity: z.number().optional(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
@@ -56,3 +57,12 @@ export const AdminPostOrderEditsItemsActionReqSchema = z.object({
|
||||
export type AdminPostOrderEditsItemsActionReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsItemsActionReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostOrderEditsUpdateItemQuantityReqSchema = z.object({
|
||||
quantity: z.number(),
|
||||
internal_note: z.string().nullish().optional(),
|
||||
})
|
||||
|
||||
export type AdminPostOrderEditsUpdateItemQuantityReqSchemaType = z.infer<
|
||||
typeof AdminPostOrderEditsUpdateItemQuantityReqSchema
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user