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:
1 parent
d828005354
commit
29dca1ca48
3 files changed
+15
-30
No files matched your search
@@ -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
|
input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData
|
||||||
}) => {
|
}) => {
|
||||||
const item = data.cart.items.find((i) => i.id === data.input.item_id)!
|
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)
|
const variantIds = [item?.variant_id].filter(Boolean)
|
||||||
return { item, variantIds }
|
return { item, variantIds }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import {
|
|||||||
deleteLineItemsWorkflowId,
|
deleteLineItemsWorkflowId,
|
||||||
updateLineItemInCartWorkflowId,
|
updateLineItemInCartWorkflowId,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { prepareListQuery } from "@medusajs/framework"
|
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
import { HttpTypes } from "@medusajs/framework/types"
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { refetchCart } from "../../../helpers"
|
import { refetchCart } from "../../../helpers"
|
||||||
import { StoreUpdateCartLineItemType } from "../../../validators"
|
import { StoreUpdateCartLineItemType } from "../../../validators"
|
||||||
|
|
||||||
@@ -13,38 +12,11 @@ export const POST = async (
|
|||||||
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
||||||
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
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)
|
const we = req.scope.resolve(Modules.WORKFLOW_ENGINE)
|
||||||
await we.run(updateLineItemInCartWorkflowId, {
|
await we.run(updateLineItemInCartWorkflowId, {
|
||||||
input: {
|
input: {
|
||||||
cart_id: req.params.id,
|
cart_id: req.params.id,
|
||||||
item_id: item.id,
|
item_id: req.params.line_id,
|
||||||
update: req.validatedBody,
|
update: req.validatedBody,
|
||||||
},
|
},
|
||||||
transactionId: "cart-update-item-" + req.params.id,
|
transactionId: "cart-update-item-" + req.params.id,
|
||||||
|
|||||||
Reference in new issue
Block a user