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
parent 5aa62e59e4
commit 617a5972bf
89 changed files with 1706 additions and 950 deletions

View File

@@ -1,13 +1,5 @@
import {
buildEntitiesNameToLinkableKeysMap,
defineJoinerConfig,
MapToConfig,
Modules,
} from "@medusajs/utils"
import { defineJoinerConfig, Modules } from "@medusajs/utils"
export const joinerConfig = defineJoinerConfig(Modules.NOTIFICATION, {
entityQueryingConfig: [{ name: "Notification" }],
models: [{ name: "Notification" }],
})
export const entityNameToLinkableKeysMap: MapToConfig =
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)

View File

@@ -1,12 +1,12 @@
import {
Context,
DAL,
InferEntityType,
INotificationModuleService,
InternalModuleDeclaration,
ModuleJoinerConfig,
ModulesSdkTypes,
NotificationTypes,
InferEntityType,
} from "@medusajs/types"
import {
InjectManager,
@@ -17,7 +17,7 @@ import {
promiseAll,
} from "@medusajs/utils"
import { Notification } from "@models"
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
import { joinerConfig } from "../joiner-config"
import NotificationProviderService from "./notification-provider"
type InjectedDependencies = {
@@ -31,7 +31,7 @@ type InjectedDependencies = {
export default class NotificationModuleService
extends MedusaService<{
Notification: { dto: NotificationTypes.NotificationDTO }
}>({ Notification }, entityNameToLinkableKeysMap)
}>({ Notification })
implements INotificationModuleService
{
protected baseRepository_: DAL.RepositoryService

View File

@@ -12,9 +12,10 @@ type InjectedDependencies = {
]: NotificationTypes.INotificationProvider
}
export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
NotificationProvider
) {
export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService<
InjectedDependencies,
typeof NotificationProvider
>(NotificationProvider) {
protected readonly notificationProviderRepository_: DAL.RepositoryService<
InferEntityType<typeof NotificationProvider>
>
@@ -50,6 +51,8 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
): Promise<InferEntityType<typeof NotificationProvider> | undefined> {
if (!this.providersCache) {
const providers = await this.notificationProviderRepository_.find()
type name = (typeof NotificationProvider)["name"]
this.providersCache = new Map(
providers.flatMap((provider) =>
provider.channels.map((c) => [c, provider])