fix(medusa): Order edit missing transaction when consuming the inventory module (#4211)
* fix(medusa): Order edit missing transaction when consuming the inventory module * Create hot-cougars-speak.md * fix missing types
This commit is contained in:
committed by
GitHub
parent
d385dd2054
commit
d76ba0cd29
7
.changeset/hot-cougars-speak.md
Normal file
7
.changeset/hot-cougars-speak.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@medusajs/inventory": patch
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix(medusa): Order edit missing transaction when consuming the inventory module
|
||||
@@ -441,7 +441,7 @@ export default class InventoryService implements IInventoryService {
|
||||
target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
|
||||
)
|
||||
async deleteReservationItemsByLineItem(
|
||||
lineItemId: string,
|
||||
lineItemId: string | string[],
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<void> {
|
||||
return await this.reservationItemService_.deleteByLineItem(
|
||||
|
||||
@@ -8,11 +8,11 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectEntityManager,
|
||||
isDefined,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
isDefined,
|
||||
} from "@medusajs/utils"
|
||||
import { EntityManager, FindManyOptions } from "typeorm"
|
||||
import { EntityManager, FindManyOptions, In } from "typeorm"
|
||||
import { InventoryLevelService } from "."
|
||||
import { ReservationItem } from "../models"
|
||||
import { buildQuery } from "../utils/build-query"
|
||||
@@ -235,21 +235,24 @@ export default class ReservationItemService {
|
||||
*/
|
||||
@InjectEntityManager()
|
||||
async deleteByLineItem(
|
||||
lineItemId: string,
|
||||
lineItemId: string | string[],
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<void> {
|
||||
const manager = context.transactionManager!
|
||||
const itemRepository = manager.getRepository(ReservationItem)
|
||||
|
||||
const itemsIds = Array.isArray(lineItemId) ? lineItemId : [lineItemId]
|
||||
|
||||
const items = await this.list(
|
||||
{ line_item_id: lineItemId },
|
||||
{ line_item_id: itemsIds },
|
||||
undefined,
|
||||
context
|
||||
)
|
||||
|
||||
const ops: Promise<unknown>[] = [
|
||||
itemRepository.softDelete({ line_item_id: lineItemId }),
|
||||
itemRepository.softDelete({ line_item_id: In(itemsIds) }),
|
||||
]
|
||||
|
||||
for (const item of items) {
|
||||
ops.push(
|
||||
this.inventoryLevelService_.adjustReservedQuantity(
|
||||
@@ -260,6 +263,7 @@ export default class ReservationItemService {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
await Promise.all(ops)
|
||||
|
||||
await this.eventBusService_?.emit?.(ReservationItemService.Events.DELETED, {
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
TaxProviderService,
|
||||
TotalsService,
|
||||
} from "./index"
|
||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { buildQuery, isString } from "../utils"
|
||||
|
||||
import EventBusService from "./event-bus"
|
||||
@@ -767,13 +767,12 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
orderEdit = await orderEditRepository.save(orderEdit)
|
||||
|
||||
if (this.inventoryService_) {
|
||||
await Promise.all(
|
||||
lineItems.map(
|
||||
async (lineItem) =>
|
||||
await this.inventoryService_!.deleteReservationItemsByLineItem(
|
||||
lineItem.id
|
||||
)
|
||||
)
|
||||
const itemsIds = lineItems.map((i) => i.id)
|
||||
await this.inventoryService_!.deleteReservationItemsByLineItem(
|
||||
itemsIds,
|
||||
{
|
||||
transactionManager: manager,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@ import {
|
||||
ICacheService,
|
||||
IEventBusService,
|
||||
IInventoryService,
|
||||
IStockLocationService,
|
||||
InventoryItemDTO,
|
||||
InventoryLevelDTO,
|
||||
IStockLocationService,
|
||||
ReservationItemDTO,
|
||||
ReserveQuantityContext,
|
||||
} from "@medusajs/types"
|
||||
import { LineItem, Product, ProductVariant } from "../models"
|
||||
import { MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { isDefined, MedusaError } from "@medusajs/utils"
|
||||
import { PricedProduct, PricedVariant } from "../types/pricing"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
|
||||
@@ -584,7 +584,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
* @param quantity quantity to release
|
||||
*/
|
||||
async deleteReservationsByLineItem(
|
||||
lineItemId: string,
|
||||
lineItemId: string | string[],
|
||||
variantId: string,
|
||||
quantity: number
|
||||
): Promise<void> {
|
||||
@@ -606,7 +606,10 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
})
|
||||
}
|
||||
|
||||
await this.inventoryService_.deleteReservationItemsByLineItem(lineItemId)
|
||||
const itemIds = Array.isArray(lineItemId) ? lineItemId : [lineItemId]
|
||||
await this.inventoryService_.deleteReservationItemsByLineItem(itemIds, {
|
||||
transactionManager: this.activeManager_,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,7 +86,7 @@ export interface IInventoryService {
|
||||
): Promise<ReservationItemDTO>
|
||||
|
||||
deleteReservationItemsByLineItem(
|
||||
lineItemId: string,
|
||||
lineItemId: string | string[],
|
||||
context?: SharedContext
|
||||
): Promise<void>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user