feat: refactor module joiner config and links generation (#7859)

* feat: refactor module joiner config and links generation

* improve typings

* WIP

* WIP

* WIP

* rename type file

* create link config

* finish typings and add utils

* improve links

* WIP typings

* finalize ExportModule utils

* finalize ExportModule utils

* fix: dml tests

* improve and fixes

* simplify typings with id changes

* add toJSON

* multiple fixes and entity builder fixes

* fix currency searchable

* fix tests

* medusa service refactoring

* cleanup

* cleanup and fixes

* make module name optional

* renaming

---------

Co-authored-by: Harminder Virk <virk.officials@gmail.com>
This commit is contained in:
Adrien de Peretti
2024-07-03 13:12:49 +02:00
committed by GitHub
co-authored by Harminder Virk
parent 5aa62e59e4
commit 617a5972bf
89 changed files with 1706 additions and 950 deletions
+4 -5
View File
@@ -1,13 +1,12 @@
import { CurrencyModuleService } from "@services"
import initialDataLoader from "./loaders/initial-data"
import { ModuleExports } from "@medusajs/types"
import { Module, Modules } from "@medusajs/utils"
const service = CurrencyModuleService
const loaders = [initialDataLoader]
export const moduleDefinition: ModuleExports = {
export default Module({
name: Modules.CURRENCY,
service,
loaders,
}
export default moduleDefinition
})
@@ -1,9 +1,4 @@
import {
buildEntitiesNameToLinkableKeysMap,
defineJoinerConfig,
MapToConfig,
Modules,
} from "@medusajs/utils"
import { defineJoinerConfig, Modules } from "@medusajs/utils"
export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
primaryKeys: ["code"],
@@ -11,6 +6,3 @@ export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
currency_code: "currency",
},
})
export const entityNameToLinkableKeysMap: MapToConfig =
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
@@ -1,7 +1,7 @@
import { model } from "@medusajs/utils"
export default model.define("currency", {
code: model.text().primaryKey().searchable(),
code: model.text().searchable().primaryKey(),
symbol: model.text(),
symbol_native: model.text(),
name: model.text().searchable(),
@@ -13,7 +13,7 @@ import {
import { MedusaService } from "@medusajs/utils"
import { Currency } from "@models"
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
import { joinerConfig } from "../joiner-config"
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
@@ -22,8 +22,8 @@ type InjectedDependencies = {
export default class CurrencyModuleService
extends MedusaService<{
Currency: { dto: CurrencyTypes.CurrencyDTO }
}>({ Currency }, entityNameToLinkableKeysMap)
Currency: { dto: CurrencyTypes.CurrencyDTO; model: typeof Currency }
}>({ Currency })
implements ICurrencyModuleService
{
protected baseRepository_: DAL.RepositoryService