chore(inventory): convert to dml (#10569)

Fixes: FRMW-2848

Co-authored-by: Harminder Virk <1706381+thetutlage@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2024-12-13 12:51:26 +00:00
committed by GitHub
co-authored by Harminder Virk
parent ae1d875fcf
commit 729eb5da7b
33 changed files with 662 additions and 593 deletions
@@ -1,8 +1,9 @@
import { Context } from "@medusajs/framework/types"
import { BigNumber, ModulesSdkUtils } from "@medusajs/framework/utils"
import { applyEntityHooks } from "../utils/apply-decorators"
import { InventoryLevel } from "@models"
import { InventoryLevelRepository } from "@repositories"
import { InventoryLevel } from "../models/inventory-level"
type InjectedDependencies = {
inventoryLevelRepository: InventoryLevelRepository
@@ -10,7 +11,7 @@ type InjectedDependencies = {
export default class InventoryLevelService extends ModulesSdkUtils.MedusaInternalService<
InjectedDependencies,
InventoryLevel
typeof InventoryLevel
>(InventoryLevel) {
protected readonly inventoryLevelRepository: InventoryLevelRepository
@@ -67,3 +68,5 @@ export default class InventoryLevelService extends ModulesSdkUtils.MedusaInterna
)
}
}
applyEntityHooks()
@@ -3,6 +3,7 @@ import {
Context,
DAL,
IInventoryService,
InferEntityType,
InternalModuleDeclaration,
InventoryTypes,
ModuleJoinerConfig,
@@ -29,6 +30,7 @@ import {
} from "@medusajs/framework/utils"
import { InventoryItem, InventoryLevel, ReservationItem } from "@models"
import { joinerConfig } from "../joiner-config"
import { applyEntityHooks } from "../utils/apply-decorators"
import InventoryLevelService from "./inventory-level"
type InjectedDependencies = {
@@ -46,6 +48,8 @@ type InventoryItemCheckLevel = {
allow_backorder?: boolean
}
applyEntityHooks()
export default class InventoryModuleService
extends MedusaService<{
InventoryItem: {
@@ -66,8 +70,12 @@ export default class InventoryModuleService
{
protected baseRepository_: DAL.RepositoryService
protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService<InventoryItem>
protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService<ReservationItem>
protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService<
typeof InventoryItem
>
protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService<
typeof ReservationItem
>
protected readonly inventoryLevelService_: InventoryLevelService
constructor(
@@ -263,7 +271,7 @@ export default class InventoryModuleService
async createReservationItems_(
input: InventoryTypes.CreateReservationItemInput[],
@MedusaContext() context: Context = {}
): Promise<ReservationItem[]> {
): Promise<InferEntityType<typeof ReservationItem>[]> {
const inventoryLevels = await this.ensureInventoryLevels(
input.map(
({ location_id, inventory_item_id, quantity, allow_backorder }) => ({
@@ -417,7 +425,7 @@ export default class InventoryModuleService
async createInventoryLevels_(
input: InventoryTypes.CreateInventoryLevelInput[],
@MedusaContext() context: Context = {}
): Promise<InventoryLevel[]> {
): Promise<InferEntityType<typeof InventoryLevel>[]> {
return await this.inventoryLevelService_.create(input, context)
}
@@ -473,7 +481,7 @@ export default class InventoryModuleService
id: string
})[],
@MedusaContext() context: Context = {}
): Promise<InventoryItem[]> {
): Promise<InferEntityType<typeof InventoryItem>[]> {
return await this.inventoryItemService_.update(input, context)
}
@@ -670,7 +678,7 @@ export default class InventoryModuleService
async updateReservationItems_(
input: (InventoryTypes.UpdateReservationItemInput & { id: string })[],
@MedusaContext() context: Context = {}
): Promise<ReservationItem[]> {
): Promise<InferEntityType<typeof ReservationItem>[]> {
const ids = input.map((u) => u.id)
const reservationItems = await this.listReservationItems(
{ id: ids },
@@ -989,7 +997,7 @@ export default class InventoryModuleService
]
}
const results: InventoryLevel[] = []
const results: InferEntityType<typeof InventoryLevel>[] = []
for (const data of all) {
const result = await this.adjustInventory_(
@@ -1024,7 +1032,7 @@ export default class InventoryModuleService
locationId: string,
adjustment: BigNumberInput,
@MedusaContext() context: Context = {}
): Promise<InventoryLevel> {
): Promise<InferEntityType<typeof InventoryLevel>> {
const inventoryLevel = await this.retrieveInventoryLevelByItemAndLocation(
inventoryItemId,
locationId,