Chore/rm main entity concept (#7709)

**What**
Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate.
This pr also includes various fixes in different modules

Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2024-06-19 13:02:16 +00:00
1 parent 2895ccfba8
commit 48963f55ef
533 files changed
+6469 -9769

No files matched your search

@@ -12,40 +12,33 @@ import {
InjectTransactionManager,
MedusaContext,
MedusaError,
ModulesSdkUtils,
MedusaService,
promiseAll,
} from "@medusajs/utils"
import { Notification } from "@models"
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
import NotificationProviderService from "./notification-provider"
import { NotificationModel, NotificationProvider } from "@models"
const generateMethodForModels = { NotificationProvider }
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
notificationModelService: ModulesSdkTypes.IMedusaInternalService<any>
notificationService: ModulesSdkTypes.IMedusaInternalService<any>
notificationProviderService: NotificationProviderService
}
export default class NotificationModuleService<
TEntity extends NotificationModel = NotificationModel
>
extends ModulesSdkUtils.MedusaService<
NotificationTypes.NotificationDTO,
{
NotificationProvider: { dto: NotificationTypes.NotificationProviderDTO }
}
>(NotificationModel, generateMethodForModels, entityNameToLinkableKeysMap)
export default class NotificationModuleService
extends MedusaService<{
Notification: { dto: NotificationTypes.NotificationDTO }
}>({ Notification }, entityNameToLinkableKeysMap)
implements INotificationModuleService
{
protected baseRepository_: DAL.RepositoryService
protected readonly notificationService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
protected readonly notificationService_: ModulesSdkTypes.IMedusaInternalService<Notification>
protected readonly notificationProviderService_: NotificationProviderService
constructor(
{
baseRepository,
notificationModelService,
notificationService,
notificationProviderService,
}: InjectedDependencies,
protected readonly moduleDeclaration: InternalModuleDeclaration
@@ -53,24 +46,26 @@ export default class NotificationModuleService<
// @ts-ignore
super(...arguments)
this.baseRepository_ = baseRepository
this.notificationService_ = notificationModelService
this.notificationService_ = notificationService
this.notificationProviderService_ = notificationProviderService
}
__joinerConfig(): ModuleJoinerConfig {
return joinerConfig
}
create(
// @ts-expect-error
createNotifications(
data: NotificationTypes.CreateNotificationDTO[],
sharedContext?: Context
): Promise<NotificationTypes.NotificationDTO[]>
create(
createNotifications(
data: NotificationTypes.CreateNotificationDTO,
sharedContext?: Context
): Promise<NotificationTypes.NotificationDTO>
@InjectManager("baseRepository_")
async create(
async createNotifications(
data:
| NotificationTypes.CreateNotificationDTO
| NotificationTypes.CreateNotificationDTO[],
@@ -80,7 +75,10 @@ export default class NotificationModuleService<
> {
const normalized = Array.isArray(data) ? data : [data]
const createdNotifications = await this.create_(normalized, sharedContext)
const createdNotifications = await this.createNotifications_(
normalized,
sharedContext
)
const serialized = await this.baseRepository_.serialize<
NotificationTypes.NotificationDTO[]
@@ -90,10 +88,10 @@ export default class NotificationModuleService<
}
@InjectTransactionManager("baseRepository_")
protected async create_(
protected async createNotifications_(
data: NotificationTypes.CreateNotificationDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<TEntity[]> {
): Promise<Notification[]> {
if (!data.length) {
return []
}