feat(medusa,core-flows): update cart adjustments on item updates (#6539)
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { updateCartPromotionsWorkflow } from "@medusajs/core-flows"
|
||||
import { PromotionActions } from "@medusajs/utils"
|
||||
import { PromotionActions, remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||
import { defaultStoreCartFields } from "../../query-config"
|
||||
import { StorePostCartsCartPromotionsReq } from "../../validators"
|
||||
|
||||
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
const workflow = updateCartPromotionsWorkflow(req.scope)
|
||||
const payload = req.validatedBody as StorePostCartsCartPromotionsReq
|
||||
|
||||
const { result, errors } = await workflow.run({
|
||||
const { errors } = await workflow.run({
|
||||
input: {
|
||||
promoCodes: payload.promo_codes,
|
||||
cartId: req.params.id,
|
||||
@@ -20,14 +22,24 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
res.status(200).json({ cart: result })
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: "cart",
|
||||
fields: defaultStoreCartFields,
|
||||
})
|
||||
|
||||
const [cart] = await remoteQuery(query, {
|
||||
cart: { id: req.params.id },
|
||||
})
|
||||
|
||||
res.status(200).json({ cart })
|
||||
}
|
||||
|
||||
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
const workflow = updateCartPromotionsWorkflow(req.scope)
|
||||
const payload = req.validatedBody as StorePostCartsCartPromotionsReq
|
||||
|
||||
const { result, errors } = await workflow.run({
|
||||
const { errors } = await workflow.run({
|
||||
input: {
|
||||
promoCodes: payload.promo_codes,
|
||||
cartId: req.params.id,
|
||||
@@ -40,5 +52,14 @@ export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
res.status(200).json({ cart: result })
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: "cart",
|
||||
fields: defaultStoreCartFields,
|
||||
})
|
||||
|
||||
const [cart] = await remoteQuery(query, {
|
||||
cart: { id: req.params.id },
|
||||
})
|
||||
|
||||
res.status(200).json({ cart })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user