fix(): update cart line item route fetching (#13477)
**What** Remove cart fetching before workflow which fetch the cart as well
This commit is contained in:
committed by
GitHub
parent
d828005354
commit
29dca1ca48
6
.changeset/spotty-hotels-speak.md
Normal file
6
.changeset/spotty-hotels-speak.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/core-flows": patch
|
||||
---
|
||||
|
||||
fix(): update cart line item route fetching
|
||||
@@ -134,6 +134,13 @@ export const updateLineItemInCartWorkflow = createWorkflow(
|
||||
input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData
|
||||
}) => {
|
||||
const item = data.cart.items.find((i) => i.id === data.input.item_id)!
|
||||
if (!item) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Line item with id: ${data.input.item_id} was not found`
|
||||
)
|
||||
}
|
||||
|
||||
const variantIds = [item?.variant_id].filter(Boolean)
|
||||
return { item, variantIds }
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ import {
|
||||
deleteLineItemsWorkflowId,
|
||||
updateLineItemInCartWorkflowId,
|
||||
} from "@medusajs/core-flows"
|
||||
import { prepareListQuery } from "@medusajs/framework"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { refetchCart } from "../../../helpers"
|
||||
import { StoreUpdateCartLineItemType } from "../../../validators"
|
||||
|
||||
@@ -13,38 +12,11 @@ export const POST = async (
|
||||
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
||||
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||
) => {
|
||||
// TODO: Move this to the workflow when the query to line item is fixed
|
||||
const cart = await refetchCart(
|
||||
req.params.id,
|
||||
req.scope,
|
||||
prepareListQuery(
|
||||
{},
|
||||
{
|
||||
defaults: [
|
||||
"id",
|
||||
"region_id",
|
||||
"customer_id",
|
||||
"sales_channel_id",
|
||||
"currency_code",
|
||||
"*items",
|
||||
],
|
||||
}
|
||||
).remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
const item = cart.items?.find((i) => i.id === req.params.line_id)
|
||||
if (!item) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Line item with id: ${req.params.line_id} was not found`
|
||||
)
|
||||
}
|
||||
|
||||
const we = req.scope.resolve(Modules.WORKFLOW_ENGINE)
|
||||
await we.run(updateLineItemInCartWorkflowId, {
|
||||
input: {
|
||||
cart_id: req.params.id,
|
||||
item_id: item.id,
|
||||
item_id: req.params.line_id,
|
||||
update: req.validatedBody,
|
||||
},
|
||||
transactionId: "cart-update-item-" + req.params.id,
|
||||
|
||||
Reference in New Issue
Block a user