feat: Fulfillment module basic structure (#6319)

**What**
Scafold the fulfillment module basic structure

**Bonus**
Simplified module scaffolding with new factories and less directories to manage
- mikro orm connection loader factory
- initialize factory

FIXES CORE-1709
FIXES CORE-1710
This commit is contained in:
Adrien de Peretti
2024-02-06 14:29:36 +01:00
committed by GitHub
parent 2104843826
commit 12054f5c01
42 changed files with 694 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ export * from "./load-module-database-config"
export * from "./decorators"
export * from "./build-query"
export * from "./loaders/mikro-orm-connection-loader"
export * from "./loaders/mikro-orm-connection-loader-factory"
export * from "./loaders/container-loader-factory"
export * from "./create-pg-connection"
export * from "./migration-scripts"

View File

@@ -0,0 +1,34 @@
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/types"
import { mikroOrmConnectionLoader } from "./mikro-orm-connection-loader"
/**
* Factory for creating a MikroORM connection loader for the modules
*
* @param moduleName
* @param moduleModels
* @param migrationsPath
*/
export function mikroOrmConnectionLoaderFactory({
moduleName,
moduleModels,
migrationsPath,
}: {
moduleName: string
moduleModels: any[]
migrationsPath?: string
}): any {
return async (
{ options, container, logger }: LoaderOptions,
moduleDeclaration?: InternalModuleDeclaration
): Promise<void> => {
await mikroOrmConnectionLoader({
moduleName,
entities: moduleModels,
container,
options,
moduleDeclaration,
logger,
pathToMigrations: migrationsPath ?? "",
})
}
}

View File

@@ -11,6 +11,16 @@ import { ContainerRegistrationKeys, MedusaError } from "../../common"
import { mikroOrmCreateConnection } from "../../dal"
import { loadDatabaseConfig } from "../load-module-database-config"
/**
* Load a MikroORM connection into the container
*
* @param moduleName
* @param container
* @param options
* @param moduleDeclaration
* @param entities
* @param pathToMigrations
*/
export async function mikroOrmConnectionLoader({
moduleName,
container,