feat(core-flows,medusa): Add API to update cart's customer (#10151)
what: - adds an endpoint that updates a cart's customer RESOLVES CMRC-718
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { updateCartCustomerWorkflow } from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { refetchCart } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||
) => {
|
||||
const workflow = updateCartCustomerWorkflow(req.scope)
|
||||
|
||||
await workflow.run({
|
||||
input: {
|
||||
id: req.params.id,
|
||||
customer_id: req.auth_context?.actor_id,
|
||||
},
|
||||
})
|
||||
|
||||
const cart = await refetchCart(
|
||||
req.params.id,
|
||||
req.scope,
|
||||
req.remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
res.status(200).json({ cart })
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { MiddlewareRoute } from "@medusajs/framework/http"
|
||||
import {
|
||||
validateAndTransformBody,
|
||||
validateAndTransformQuery,
|
||||
} from "@medusajs/framework"
|
||||
import { authenticate, MiddlewareRoute } from "@medusajs/framework/http"
|
||||
import { ensurePublishableKeyAndSalesChannelMatch } from "../../utils/middlewares/common/ensure-pub-key-sales-channel-match"
|
||||
import { maybeAttachPublishableKeyScopes } from "../../utils/middlewares/common/maybe-attach-pub-key-scopes"
|
||||
import { validateAndTransformBody } from "@medusajs/framework"
|
||||
import { validateAndTransformQuery } from "@medusajs/framework"
|
||||
import * as OrderQueryConfig from "../orders/query-config"
|
||||
import { StoreGetOrderParams } from "../orders/validators"
|
||||
import * as QueryConfig from "./query-config"
|
||||
@@ -15,6 +17,7 @@ import {
|
||||
StoreGetCartsCart,
|
||||
StoreRemoveCartPromotions,
|
||||
StoreUpdateCart,
|
||||
StoreUpdateCartCustomer,
|
||||
StoreUpdateCartLineItem,
|
||||
} from "./validators"
|
||||
|
||||
@@ -53,6 +56,18 @@ export const storeCartRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/store/carts/:id/customer",
|
||||
middlewares: [
|
||||
authenticate("customer", ["session", "bearer"]),
|
||||
validateAndTransformBody(StoreUpdateCartCustomer),
|
||||
validateAndTransformQuery(
|
||||
StoreGetCartsCart,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/store/carts/:id/line-items",
|
||||
|
||||
@@ -91,3 +91,8 @@ export type StoreCreateCartPaymentCollectionType = z.infer<
|
||||
typeof StoreCreateCartPaymentCollection
|
||||
>
|
||||
export const StoreCreateCartPaymentCollection = z.object({}).strict()
|
||||
|
||||
export type StoreUpdateCartCustomerType = z.infer<
|
||||
typeof StoreUpdateCartCustomer
|
||||
>
|
||||
export const StoreUpdateCartCustomer = z.object({}).strict()
|
||||
|
||||
Reference in New Issue
Block a user