feat(core-flows,medusa): Add customer validation on cart update (#9662)

This commit is contained in:
Riqwan Thamir
2024-10-22 12:19:12 +02:00
committed by GitHub
parent 68cb7d0b27
commit 0d803b3f2d
6 changed files with 231 additions and 62 deletions
@@ -1,11 +1,15 @@
import { updateCartWorkflow } from "@medusajs/core-flows"
import { updateCartWorkflowWithCustomerValidation } from "@medusajs/core-flows"
import {
AdditionalData,
HttpTypes,
UpdateCartDataDTO,
} from "@medusajs/framework/types"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import {
AuthenticatedMedusaRequest,
MedusaRequest,
MedusaResponse,
} from "@medusajs/framework/http"
import { refetchCart } from "../helpers"
export const GET = async (
@@ -22,17 +26,15 @@ export const GET = async (
}
export const POST = async (
req: MedusaRequest<UpdateCartDataDTO & AdditionalData>,
res: MedusaResponse<{
cart: HttpTypes.StoreCart
}>
req: AuthenticatedMedusaRequest<UpdateCartDataDTO & AdditionalData>,
res: MedusaResponse<HttpTypes.StoreCartResponse>
) => {
const workflow = updateCartWorkflow(req.scope)
const workflow = updateCartWorkflowWithCustomerValidation(req.scope)
await workflow.run({
input: {
...req.validatedBody,
id: req.params.id,
auth_customer_id: req.auth_context?.actor_id,
},
})
@@ -46,6 +46,7 @@ export const StoreRemoveCartPromotions = z
export type StoreUpdateCartType = z.infer<typeof UpdateCart>
export const UpdateCart = z
.object({
customer_id: z.string().optional(),
region_id: z.string().optional(),
email: z.string().email().nullish(),
billing_address: z.union([AddressPayload, z.string()]).optional(),