feat(medusa): Modules initializer (#3352)
This commit is contained in:
@@ -6,9 +6,10 @@ import {
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { DataSource, DataSourceOptions } from "typeorm"
|
||||
|
||||
import * as InventoryModels from "../models"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { asValue } from "awilix"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import * as InventoryModels from "../models"
|
||||
import { InventoryServiceInitializeOptions } from "../types"
|
||||
|
||||
export default async (
|
||||
{ options, container }: LoaderOptions,
|
||||
@@ -21,7 +22,8 @@ export default async (
|
||||
return
|
||||
}
|
||||
|
||||
const dbData = options?.database as Record<string, string>
|
||||
const dbData =
|
||||
options?.database as InventoryServiceInitializeOptions["database"]
|
||||
|
||||
if (!dbData) {
|
||||
throw new MedusaError(
|
||||
@@ -32,13 +34,13 @@ export default async (
|
||||
|
||||
const entities = Object.values(InventoryModels)
|
||||
const dataSource = new DataSource({
|
||||
type: dbData.database_type,
|
||||
url: dbData.database_url,
|
||||
database: dbData.database_database,
|
||||
extra: dbData.database_extra || {},
|
||||
schema: dbData.database_schema,
|
||||
type: dbData.type,
|
||||
url: dbData.url,
|
||||
database: dbData.database,
|
||||
extra: dbData.extra || {},
|
||||
schema: dbData.schema,
|
||||
entities,
|
||||
logging: dbData.database_logging,
|
||||
logging: dbData.logging,
|
||||
} as DataSourceOptions)
|
||||
|
||||
await dataSource.initialize()
|
||||
|
||||
@@ -3,7 +3,7 @@ import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
InventoryItemService,
|
||||
InventoryLevelService,
|
||||
ReservationItemService,
|
||||
ReservationItemService
|
||||
} from "../services"
|
||||
|
||||
import { asClass } from "awilix"
|
||||
|
||||
Reference in New Issue
Block a user