Fix(inventory, stock-location): Remove orphaned location levels and reservations (#3460)

**What**
- Remove related inventory levels and reservation items when a stock location is removed

**How**
- Add bulk deletion methods for both inventory levels and reservation items to the inventory service api
- invoke both on location removal

Fixes CORE-1232
This commit is contained in:
Philip Korsholm authored and GitHub committed 2023-03-15 09:12:46 +00:00
1 parent fe9eea4c18
commit 10bf05c147
8 files changed
+155 -9

No files matched your search

@@ -1,5 +1,8 @@
import { EntityManager } from "typeorm"
import { IStockLocationService } from "../../../../interfaces"
import {
IInventoryService,
IStockLocationService,
} from "../../../../interfaces"
import { SalesChannelLocationService } from "../../../../services"
/**
@@ -60,6 +63,9 @@ export default async (req, res) => {
"stockLocationService"
)
const inventoryService: IInventoryService =
req.scope.resolve("inventoryService")
const salesChannelLocationService: SalesChannelLocationService =
req.scope.resolve("salesChannelLocationService")
@@ -70,6 +76,17 @@ export default async (req, res) => {
.removeLocation(id)
await stockLocationService.withTransaction(transactionManager).delete(id)
if (inventoryService) {
await Promise.all([
inventoryService
.withTransaction(transactionManager)
.deleteInventoryItemLevelByLocationId(id),
inventoryService
.withTransaction(transactionManager)
.deleteReservationItemByLocationId(id),
])
}
})
res.status(200).send({
@@ -77,6 +77,10 @@ export interface IInventoryService {
deleteInventoryItem(inventoryItemId: string): Promise<void>
deleteInventoryItemLevelByLocationId(locationId: string): Promise<void>
deleteReservationItemByLocationId(locationId: string): Promise<void>
deleteInventoryLevel(
inventoryLevelId: string,
locationId: string