feat(utils,currency): Migrate currency to use DML (#7807)
This commit is contained in:
@@ -279,4 +279,37 @@ describe("defineJoiner", () => {
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a full joiner configuration with custom aliases overriding defaults", () => {
|
||||
const joinerConfig = defineJoinerConfig(Modules.FULFILLMENT, {
|
||||
entityQueryingConfig: [FulfillmentSet],
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
args: {
|
||||
entity: "FulfillmentSet",
|
||||
methodSuffix: "fulfillmentSetCustom",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
expect(joinerConfig).toEqual({
|
||||
serviceName: Modules.FULFILLMENT,
|
||||
primaryKeys: ["id"],
|
||||
schema: undefined,
|
||||
linkableKeys: {
|
||||
fulfillment_set_id: FulfillmentSet.name,
|
||||
},
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
args: {
|
||||
entity: "FulfillmentSet",
|
||||
methodSuffix: "fulfillmentSetCustom",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
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"
|
||||
export * from "./medusa-internal-service"
|
||||
export * from "./medusa-service"
|
||||
export * from "./decorators"
|
||||
export * from "./definition"
|
||||
export * from "./event-builder-factory"
|
||||
export * from "./joiner-config-builder"
|
||||
export * from "./load-module-database-config"
|
||||
export * from "./loaders/container-loader-factory"
|
||||
export * from "./loaders/load-models"
|
||||
export * from "./loaders/mikro-orm-connection-loader"
|
||||
export * from "./loaders/mikro-orm-connection-loader-factory"
|
||||
export * from "./medusa-internal-service"
|
||||
export * from "./medusa-service"
|
||||
export * from "./migration-scripts"
|
||||
export * from "./mikro-orm-cli-config-builder"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { JoinerServiceConfigAlias, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { join } from "path"
|
||||
import {
|
||||
camelToSnakeCase,
|
||||
deduplicate,
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
pluralize,
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
import { join } from "path"
|
||||
import { loadModels } from "./loaders/load-models"
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ export function defineJoinerConfig(
|
||||
linkableKeys,
|
||||
primaryKeys,
|
||||
}: {
|
||||
alias?: ModuleJoinerConfig["alias"]
|
||||
alias?: JoinerServiceConfigAlias[]
|
||||
schema?: string
|
||||
entityQueryingConfig?: { name: string }[]
|
||||
linkableKeys?: Record<string, string>
|
||||
@@ -79,16 +79,22 @@ export function defineJoinerConfig(
|
||||
pluralize(upperCaseFirst(alias.args.entity)),
|
||||
},
|
||||
})),
|
||||
...models.map((entity, i) => ({
|
||||
name: [
|
||||
`${camelToSnakeCase(entity.name).toLowerCase()}`,
|
||||
`${pluralize(camelToSnakeCase(entity.name).toLowerCase())}`,
|
||||
],
|
||||
args: {
|
||||
entity: entity.name,
|
||||
methodSuffix: pluralize(upperCaseFirst(entity.name)),
|
||||
},
|
||||
})),
|
||||
...models
|
||||
.filter((model) => {
|
||||
return (
|
||||
!alias || !alias.some((alias) => alias.args?.entity === model.name)
|
||||
)
|
||||
})
|
||||
.map((entity, i) => ({
|
||||
name: [
|
||||
`${camelToSnakeCase(entity.name).toLowerCase()}`,
|
||||
`${pluralize(camelToSnakeCase(entity.name).toLowerCase())}`,
|
||||
],
|
||||
args: {
|
||||
entity: entity.name,
|
||||
methodSuffix: pluralize(upperCaseFirst(entity.name)),
|
||||
},
|
||||
})),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,11 @@ export function loadModels(basePath: string) {
|
||||
|
||||
if (stats.isFile()) {
|
||||
try {
|
||||
const required = require(filePath)
|
||||
return Object.values(required).filter(
|
||||
(resource) => typeof resource === "function" && !!resource.name
|
||||
)
|
||||
const required = require(filePath) as {
|
||||
[key: string]: { name?: string }
|
||||
}
|
||||
|
||||
return Object.values(required).filter((resource) => !!resource.name)
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { MikroORMOptions } from "@mikro-orm/core/utils/Configuration"
|
||||
import { IDmlEntity } from "@medusajs/types"
|
||||
import { DmlEntity, toMikroORMEntity } from "../dml"
|
||||
import { TSMigrationGenerator } from "../dal"
|
||||
import { AnyEntity, EntityClassGroup, EntitySchema } from "@mikro-orm/core"
|
||||
@@ -11,7 +10,7 @@ type Options = Partial<MikroORMOptions> & {
|
||||
| EntityClass<AnyEntity>
|
||||
| EntityClassGroup<AnyEntity>
|
||||
| EntitySchema
|
||||
| IDmlEntity<any>
|
||||
| DmlEntity<any>
|
||||
)[]
|
||||
databaseName: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user