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:
co-authored by
Stevche Radevski
Oli Juhl
parent
2895ccfba8
commit
48963f55ef
@@ -10,29 +10,24 @@ import {
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
|
||||
import { Currency } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
const generateMethodForModels = {}
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
currencyService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class CurrencyModuleService<TEntity extends Currency = Currency>
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CurrencyTypes.CurrencyDTO,
|
||||
{
|
||||
Currency: { dto: CurrencyTypes.CurrencyDTO }
|
||||
}
|
||||
>(Currency, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
export default class CurrencyModuleService
|
||||
extends MedusaService<{
|
||||
Currency: { dto: CurrencyTypes.CurrencyDTO }
|
||||
}>({ Currency }, entityNameToLinkableKeysMap)
|
||||
implements ICurrencyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService<Currency>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, currencyService }: InjectedDependencies,
|
||||
@@ -48,36 +43,39 @@ export default class CurrencyModuleService<TEntity extends Currency = Currency>
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
retrieve(
|
||||
// @ts-expect-error
|
||||
async retrieveCurrency(
|
||||
code: string,
|
||||
config?: FindConfig<CurrencyTypes.CurrencyDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<CurrencyTypes.CurrencyDTO> {
|
||||
return this.currencyService_.retrieve(
|
||||
code?.toLowerCase(),
|
||||
return await super.retrieveCurrency(
|
||||
CurrencyModuleService.normalizeFilters({ code: [code] })!.code![0],
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
list(
|
||||
// @ts-expect-error
|
||||
async listCurrencies(
|
||||
filters?: FilterableCurrencyProps,
|
||||
config?: FindConfig<CurrencyTypes.CurrencyDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<CurrencyTypes.CurrencyDTO[]> {
|
||||
return this.currencyService_.list(
|
||||
return await super.listCurrencies(
|
||||
CurrencyModuleService.normalizeFilters(filters),
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
listAndCount(
|
||||
// @ts-expect-error
|
||||
async listAndCountCurrencies(
|
||||
filters?: FilterableCurrencyProps,
|
||||
config?: FindConfig<CurrencyTypes.CurrencyDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<[CurrencyTypes.CurrencyDTO[], number]> {
|
||||
return this.currencyService_.listAndCount(
|
||||
return await super.listAndCountCurrencies(
|
||||
CurrencyModuleService.normalizeFilters(filters),
|
||||
config,
|
||||
sharedContext
|
||||
|
||||
Reference in New Issue
Block a user