Files
medusa-store/packages/inventory-next/src/services/inventory-level.ts
Philip Korsholm c19d276458 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>
2024-03-08 14:09:05 +01:00

80 lines
1.9 KiB
TypeScript

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
)
}
}