Feat(modules-sdk,inventory,stock-location): modules isolated connection (#3329)

* feat: scoped container for modules
This commit is contained in:
Carlos R. L. Rodrigues
2023-03-15 12:09:45 -03:00
committed by GitHub
parent 8e78c533c4
commit 77d46220c2
65 changed files with 1116 additions and 1011 deletions
+16 -28
View File
@@ -1,7 +1,4 @@
import {
ConfigurableModuleDeclaration,
MODULE_RESOURCE_TYPE,
} from "@medusajs/modules-sdk"
import { InternalModuleDeclaration } from "@medusajs/modules-sdk"
import {
CreateInventoryItemInput,
@@ -22,18 +19,20 @@ import {
} from "@medusajs/medusa"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import {
InventoryItemService,
InventoryLevelService,
ReservationItemService,
} from "./"
import { EntityManager } from "typeorm"
type InjectedDependencies = {
manager: EntityManager
eventBusService: IEventBusService
inventoryItemService: InventoryItemService
inventoryLevelService: InventoryLevelService
reservationItemService: ReservationItemService
}
export default class InventoryService
extends TransactionBaseService
implements IInventoryService
@@ -44,34 +43,23 @@ export default class InventoryService
protected readonly inventoryLevelService_: InventoryLevelService
constructor(
{ eventBusService, manager }: InjectedDependencies,
{
eventBusService,
manager,
inventoryItemService,
inventoryLevelService,
reservationItemService,
}: InjectedDependencies,
options?: unknown,
moduleDeclaration?: ConfigurableModuleDeclaration
moduleDeclaration?: InternalModuleDeclaration
) {
// @ts-ignore
super(...arguments)
if (moduleDeclaration?.resources !== MODULE_RESOURCE_TYPE.SHARED) {
throw new MedusaError(
MedusaError.Types.INVALID_ARGUMENT,
"At the moment this module can only be used with shared resources"
)
}
this.eventBusService_ = eventBusService
this.inventoryItemService_ = new InventoryItemService({
eventBusService,
manager,
})
this.inventoryLevelService_ = new InventoryLevelService({
eventBusService,
manager,
})
this.reservationItemService_ = new ReservationItemService({
eventBusService,
manager,
inventoryLevelService: this.inventoryLevelService_,
})
this.inventoryItemService_ = inventoryItemService
this.inventoryLevelService_ = inventoryLevelService
this.reservationItemService_ = reservationItemService
}
/**