fix: product module joiner config (#8170)

* fix: product module joiner config

* fix aliases

* revert package.json

* add js doc
This commit is contained in:
Adrien de Peretti
2024-07-18 11:27:21 +02:00
committed by GitHub
parent c58a35f0c0
commit 398e39d163
2 changed files with 97 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { LinkModulesExtraFields, ModuleJoinerConfig } from "@medusajs/types"
import { isObject, pluralize, toPascalCase } from "../common"
import { camelToSnakeCase, isObject, pluralize, toPascalCase } from "../common"
import { composeLinkName } from "../link"
export const DefineLinkSymbol = Symbol.for("DefineLink")
@@ -74,7 +74,7 @@ function prepareServiceConfig(input: DefineLinkInputSource) {
serviceConfig = {
key: source.linkable,
alias: source.field,
alias: camelToSnakeCase(source.field),
primaryKey: source.primaryKey,
isList: false,
deleteCascade: false,
@@ -87,7 +87,7 @@ function prepareServiceConfig(input: DefineLinkInputSource) {
serviceConfig = {
key: source.linkable,
alias: source.field,
alias: camelToSnakeCase(source.field),
primaryKey: source.primaryKey,
isList: input.isList ?? false,
deleteCascade: input.deleteCascade ?? false,
@@ -106,6 +106,14 @@ function prepareServiceConfig(input: DefineLinkInputSource) {
return serviceConfig
}
/**
* Generate a ModuleJoinerConfig for the link definition on the fly.
* All naming, aliases etc are following our conventional naming.
*
* @param leftService
* @param rightService
* @param linkServiceOptions
*/
export function defineLink(
leftService: DefineLinkInputSource,
rightService: DefineLinkInputSource,