chore(): improve inventory module (#13463)
RESOVLES CORE-1185 **What** Reduce higher function call to reduce overserialization
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/inventory": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(): improve inventory module
|
||||||
@@ -123,7 +123,7 @@ export default class InventoryModuleService
|
|||||||
{ location_id: string; inventory_item_id: string }[]
|
{ location_id: string; inventory_item_id: string }[]
|
||||||
]
|
]
|
||||||
|
|
||||||
const inventoryLevels = await this.listInventoryLevels(
|
const inventoryLevels = await this.inventoryLevelService_.list(
|
||||||
{
|
{
|
||||||
$or: [
|
$or: [
|
||||||
{ id: idData.filter(({ id }) => !!id).map((e) => e.id) },
|
{ id: idData.filter(({ id }) => !!id).map((e) => e.id) },
|
||||||
@@ -588,7 +588,7 @@ export default class InventoryModuleService
|
|||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<InferEntityType<typeof ReservationItem>[]> {
|
): Promise<InferEntityType<typeof ReservationItem>[]> {
|
||||||
const ids = input.map((u) => u.id)
|
const ids = input.map((u) => u.id)
|
||||||
const reservationItems = await this.listReservationItems(
|
const reservationItems = await this.reservationItemService_.list(
|
||||||
{ id: ids },
|
{ id: ids },
|
||||||
{},
|
{},
|
||||||
context
|
context
|
||||||
@@ -729,9 +729,9 @@ export default class InventoryModuleService
|
|||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const reservations: InventoryTypes.ReservationItemDTO[] =
|
const reservations: InventoryTypes.ReservationItemDTO[] =
|
||||||
await super.listReservationItems({ id: ids }, {}, context)
|
await this.reservationItemService_.list({ id: ids }, {}, context)
|
||||||
|
|
||||||
await super.softDeleteReservationItems({ id: ids }, config, context)
|
await super.softDeleteReservationItems(ids, config, context)
|
||||||
|
|
||||||
await this.adjustInventoryLevelsForReservationsDeletion(
|
await this.adjustInventoryLevelsForReservationsDeletion(
|
||||||
reservations,
|
reservations,
|
||||||
@@ -782,7 +782,11 @@ export default class InventoryModuleService
|
|||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const reservations: InventoryTypes.ReservationItemDTO[] =
|
const reservations: InventoryTypes.ReservationItemDTO[] =
|
||||||
await this.listReservationItems({ location_id: locationId }, {}, context)
|
await this.reservationItemService_.list(
|
||||||
|
{ location_id: locationId },
|
||||||
|
{},
|
||||||
|
context
|
||||||
|
)
|
||||||
|
|
||||||
await this.reservationItemService_.softDelete(
|
await this.reservationItemService_.softDelete(
|
||||||
{ location_id: locationId },
|
{ location_id: locationId },
|
||||||
@@ -816,7 +820,11 @@ export default class InventoryModuleService
|
|||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const reservations: InventoryTypes.ReservationItemDTO[] =
|
const reservations: InventoryTypes.ReservationItemDTO[] =
|
||||||
await this.listReservationItems({ line_item_id: lineItemId }, {}, context)
|
await this.reservationItemService_.list(
|
||||||
|
{ line_item_id: lineItemId },
|
||||||
|
{},
|
||||||
|
context
|
||||||
|
)
|
||||||
|
|
||||||
await this.reservationItemService_.softDelete(
|
await this.reservationItemService_.softDelete(
|
||||||
{ line_item_id: lineItemId },
|
{ line_item_id: lineItemId },
|
||||||
@@ -850,7 +858,11 @@ export default class InventoryModuleService
|
|||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const reservations: InventoryTypes.ReservationItemDTO[] =
|
const reservations: InventoryTypes.ReservationItemDTO[] =
|
||||||
await this.listReservationItems({ line_item_id: lineItemId }, {}, context)
|
await this.reservationItemService_.list(
|
||||||
|
{ line_item_id: lineItemId },
|
||||||
|
{},
|
||||||
|
context
|
||||||
|
)
|
||||||
|
|
||||||
await this.reservationItemService_.restore(
|
await this.reservationItemService_.restore(
|
||||||
{ line_item_id: lineItemId },
|
{ line_item_id: lineItemId },
|
||||||
@@ -934,12 +946,19 @@ export default class InventoryModuleService
|
|||||||
adjustment: BigNumberInput,
|
adjustment: BigNumberInput,
|
||||||
@MedusaContext() context: Context = {}
|
@MedusaContext() context: Context = {}
|
||||||
): Promise<InferEntityType<typeof InventoryLevel>> {
|
): Promise<InferEntityType<typeof InventoryLevel>> {
|
||||||
const inventoryLevel = await this.retrieveInventoryLevelByItemAndLocation(
|
const [inventoryLevel] = await this.inventoryLevelService_.list(
|
||||||
inventoryItemId,
|
{ inventory_item_id: inventoryItemId, location_id: locationId },
|
||||||
locationId,
|
{},
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!inventoryLevel) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`Inventory level for item ${inventoryItemId} and location ${locationId} not found`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.inventoryLevelService_.update(
|
const result = await this.inventoryLevelService_.update(
|
||||||
{
|
{
|
||||||
id: inventoryLevel.id,
|
id: inventoryLevel.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user