fix(medusa): Missing withTransaction on update in get-cart.ts (#3246)

This commit is contained in:
Adrien de Peretti
2023-02-13 16:30:46 +01:00
committed by GitHub
parent a2cc084db8
commit bbbb3d8882
2 changed files with 11 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Get cart missing transaction on update

View File

@@ -1,4 +1,5 @@
import { CartService } from "../../../../services"
import { EntityManager } from "typeorm"
/**
* @oas [get] /carts/{id}
@@ -47,6 +48,7 @@ export default async (req, res) => {
const { id } = req.params
const cartService: CartService = req.scope.resolve("cartService")
const manager: EntityManager = req.scope.resolve("manager")
const cart = await cartService.retrieve(id, {
select: ["id", "customer_id"],
@@ -59,8 +61,10 @@ export default async (req, res) => {
!cart.email ||
cart.customer_id !== req.user.customer_id
) {
await cartService.update(id, {
customer_id: req.user.customer_id,
await manager.transaction(async (transctionManager) => {
await cartService.withTransaction(transctionManager).update(id, {
customer_id: req.user.customer_id,
})
})
}
}