feat(inventory-next, types): inventory module conversion (#6596)

* init

* create new interface

* prep integration tests

* update denpencies

* inventory service partial tests

* finalize integration tests

* add events

* align events

* adjust inventory level reservation levels

* add test validating reserved quantity after reseration item update

* fix nits

* rename to inventory-next

* update yarn.lock

* remove changelog

* remove fixtures

* remove unused files

* ready for review

* Update packages/inventory-next/package.json

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* pr feedback

* add tests and docs for partition-array util

* remote decorators from private method

* fix unit tests

* add migrations

* add foreign keys

* fix build

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2024-03-08 14:09:05 +01:00
committed by GitHub
co-authored by Oli Juhl
parent 8406eb5a35
commit c19d276458
46 changed files with 4896 additions and 14 deletions
@@ -0,0 +1,5 @@
describe("noop", function () {
it("should run", function () {
expect(true).toBe(true)
})
})
@@ -0,0 +1,2 @@
export { default as InventoryModuleService } from "./inventory"
export { default as InventoryLevelService } from "./inventory-level"
@@ -0,0 +1,79 @@
import {
Context,
CreateInventoryLevelInput,
DAL,
SharedContext,
} from "@medusajs/types"
import {
InjectTransactionManager,
MedusaContext,
ModulesSdkUtils,
} from "@medusajs/utils"
import { InventoryLevel } from "../models/inventory-level"
import { InventoryLevelRepository } from "@repositories"
type InjectedDependencies = {
inventoryLevelRepository: InventoryLevelRepository
}
export default class InventoryLevelService<
TEntity extends InventoryLevel = InventoryLevel
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
InventoryLevel
)<TEntity> {
protected readonly inventoryLevelRepository: InventoryLevelRepository
constructor(container: InjectedDependencies) {
super(container)
this.inventoryLevelRepository = container.inventoryLevelRepository
}
async retrieveStockedQuantity(
inventoryItemId: string,
locationIds: string[] | string,
context: Context = {}
): Promise<number> {
const locationIdArray = Array.isArray(locationIds)
? locationIds
: [locationIds]
return await this.inventoryLevelRepository.getStockedQuantity(
inventoryItemId,
locationIdArray,
context
)
}
async getAvailableQuantity(
inventoryItemId: string,
locationIds: string[] | string,
context: Context = {}
): Promise<number> {
const locationIdArray = Array.isArray(locationIds)
? locationIds
: [locationIds]
return await this.inventoryLevelRepository.getAvailableQuantity(
inventoryItemId,
locationIdArray,
context
)
}
async getReservedQuantity(
inventoryItemId: string,
locationIds: string[] | string,
context: Context = {}
) {
if (!Array.isArray(locationIds)) {
locationIds = [locationIds]
}
return await this.inventoryLevelRepository.getReservedQuantity(
inventoryItemId,
locationIds,
context
)
}
}
File diff suppressed because it is too large Load Diff