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:
Adrien de Peretti
2024-06-19 13:02:16 +00:00
committed by GitHub
co-authored by Stevche Radevski Oli Juhl
parent 2895ccfba8
commit 48963f55ef
533 changed files with 6469 additions and 9769 deletions
@@ -15,7 +15,7 @@ import {
InjectTransactionManager,
isString,
MedusaContext,
ModulesSdkUtils,
MedusaService,
promiseAll,
} from "@medusajs/utils"
@@ -30,18 +30,15 @@ type InjectedDependencies = {
salesChannelService: ModulesSdkTypes.IMedusaInternalService<any>
}
export default class SalesChannelModuleService<
TEntity extends SalesChannel = SalesChannel
>
extends ModulesSdkUtils.MedusaService<SalesChannelDTO>(
SalesChannel,
{},
export default class SalesChannelModuleService
extends MedusaService<{ SalesChannel: { dto: SalesChannelDTO } }>(
{ SalesChannel },
entityNameToLinkableKeysMap
)
implements ISalesChannelModuleService
{
protected baseRepository_: DAL.RepositoryService
protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<SalesChannel>
constructor(
{ baseRepository, salesChannelService }: InjectedDependencies,
@@ -57,22 +54,24 @@ export default class SalesChannelModuleService<
return joinerConfig
}
async create(
// @ts-expect-error
async createSalesChannels(
data: CreateSalesChannelDTO[],
sharedContext?: Context
): Promise<SalesChannelDTO[]>
async create(
async createSalesChannels(
data: CreateSalesChannelDTO,
sharedContext?: Context
): Promise<SalesChannelDTO>
@InjectManager("baseRepository_")
async create(
async createSalesChannels(
data: CreateSalesChannelDTO | CreateSalesChannelDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<SalesChannelDTO | SalesChannelDTO[]> {
const input = Array.isArray(data) ? data : [data]
const result = await this.create_(input, sharedContext)
const result = await this.createSalesChannels_(input, sharedContext)
return await this.baseRepository_.serialize<SalesChannelDTO[]>(
Array.isArray(data) ? result : result[0],
@@ -83,25 +82,27 @@ export default class SalesChannelModuleService<
}
@InjectTransactionManager("baseRepository_")
async create_(
async createSalesChannels_(
data: CreateSalesChannelDTO[],
@MedusaContext() sharedContext: Context
): Promise<SalesChannel[]> {
return await this.salesChannelService_.create(data, sharedContext)
}
async update(
// @ts-expect-error
async updateSalesChannels(
id: string,
data: UpdateSalesChannelDTO,
sharedContext?: Context
): Promise<SalesChannelDTO>
async update(
async updateSalesChannels(
selector: FilterableSalesChannelProps,
data: UpdateSalesChannelDTO,
sharedContext?: Context
): Promise<SalesChannelDTO[]>
@InjectManager("baseRepository_")
async update(
async updateSalesChannels(
idOrSelector: string | FilterableSalesChannelProps,
data: UpdateSalesChannelDTO | UpdateSalesChannelDTO[],
@MedusaContext() sharedContext: Context = {}
@@ -122,7 +123,10 @@ export default class SalesChannelModuleService<
}))
}
const result = await this.update_(normalizedInput, sharedContext)
const result = await this.updateSalesChannels_(
normalizedInput,
sharedContext
)
return await this.baseRepository_.serialize<SalesChannelDTO[]>(
Array.isArray(data) ? result : result[0],
@@ -133,20 +137,23 @@ export default class SalesChannelModuleService<
}
@InjectTransactionManager("baseRepository_")
async update_(data: UpdateSalesChannelDTO[], sharedContext: Context) {
async updateSalesChannels_(
data: UpdateSalesChannelDTO[],
sharedContext: Context
) {
return await this.salesChannelService_.update(data, sharedContext)
}
async upsert(
async upsertSalesChannels(
data: UpsertSalesChannelDTO[],
sharedContext?: Context
): Promise<SalesChannelDTO[]>
async upsert(
async upsertSalesChannels(
data: UpsertSalesChannelDTO,
sharedContext?: Context
): Promise<SalesChannelDTO>
@InjectTransactionManager("baseRepository_")
async upsert(
async upsertSalesChannels(
data: UpsertSalesChannelDTO | UpsertSalesChannelDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<SalesChannelDTO | SalesChannelDTO[]> {
@@ -161,10 +168,10 @@ export default class SalesChannelModuleService<
const operations: Promise<SalesChannel[]>[] = []
if (forCreate.length) {
operations.push(this.create_(forCreate, sharedContext))
operations.push(this.createSalesChannels_(forCreate, sharedContext))
}
if (forUpdate.length) {
operations.push(this.update_(forUpdate, sharedContext))
operations.push(this.updateSalesChannels_(forUpdate, sharedContext))
}
const result = (await promiseAll(operations)).flat()