chore: Refactor and improve abstract module service factory (#7688)
* chore: Refactor and improve abstract module service factory * align naming * clean up some template args and tests * partially migrate modules * partially migrate modules * migrate more modules * migrate last modules * fix typings * rename interface * rename interface * fixes * fixes * rm local plain tests
This commit is contained in:
committed by
GitHub
parent
c57223a3a2
commit
d2a5201eeb
@@ -9,9 +9,10 @@ import { MedusaContainer } from "../common"
|
||||
import { RepositoryService } from "../dal"
|
||||
import { Logger } from "../logger"
|
||||
|
||||
export type Constructor<T> = new (...args: any[]) => T
|
||||
export type Constructor<T> = new (...args: any[]) => T | (new () => T)
|
||||
|
||||
export * from "../common/medusa-container"
|
||||
export * from "./internal-module-service"
|
||||
export * from "./medusa-internal-service"
|
||||
export * from "./module-provider"
|
||||
|
||||
export type LogLevel =
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
UpsertWithReplaceConfig,
|
||||
} from "../dal"
|
||||
|
||||
export interface InternalModuleService<
|
||||
export interface IMedusaInternalService<
|
||||
TEntity extends {},
|
||||
TContainer extends object = object
|
||||
> {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { internalModuleServiceFactory } from "../internal-module-service-factory"
|
||||
import { MedusaInternalService } from "../medusa-internal-service"
|
||||
import { lowerCaseFirst } from "../../common"
|
||||
|
||||
const defaultContext = { __type: "MedusaContext" }
|
||||
@@ -39,14 +39,14 @@ describe("Internal Module Service Factory", () => {
|
||||
},
|
||||
}
|
||||
|
||||
const internalModuleService = internalModuleServiceFactory<any>(Model)
|
||||
const IMedusaInternalService = MedusaInternalService<any>(Model)
|
||||
|
||||
describe("Internal Module Service Methods", () => {
|
||||
let instance
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
instance = new internalModuleService(containerMock)
|
||||
instance = new IMedusaInternalService(containerMock)
|
||||
})
|
||||
|
||||
it("should throw model id undefined error on retrieve if id is not defined", async () => {
|
||||
@@ -62,10 +62,10 @@ describe("Internal Module Service Factory", () => {
|
||||
static meta = { primaryKeys: ["id", "name"] }
|
||||
}
|
||||
|
||||
const compositeInternalModuleService =
|
||||
internalModuleServiceFactory<any>(CompositeModel)
|
||||
const compositeIMedusaInternalService =
|
||||
MedusaInternalService<any>(CompositeModel)
|
||||
|
||||
const instance = new compositeInternalModuleService(containerMock)
|
||||
const instance = new compositeIMedusaInternalService(containerMock)
|
||||
|
||||
const err = await instance.retrieve().catch((e) => e)
|
||||
expect(err.message).toBe("compositeModel - id, name must be defined")
|
||||
@@ -94,10 +94,10 @@ describe("Internal Module Service Factory", () => {
|
||||
static meta = { primaryKeys: ["id", "name"] }
|
||||
}
|
||||
|
||||
const compositeInternalModuleService =
|
||||
internalModuleServiceFactory<any>(CompositeModel)
|
||||
const compositeIMedusaInternalService =
|
||||
MedusaInternalService<any>(CompositeModel)
|
||||
|
||||
const instance = new compositeInternalModuleService(containerMock)
|
||||
const instance = new compositeIMedusaInternalService(containerMock)
|
||||
|
||||
const entity = { id: "1", name: "Item" }
|
||||
containerMock[
|
||||
@@ -1,4 +1,4 @@
|
||||
import { abstractModuleServiceFactory } from "../abstract-module-service-factory"
|
||||
import { MedusaService } from "../medusa-service"
|
||||
|
||||
const baseRepoMock = {
|
||||
serialize: jest.fn().mockImplementation((item) => item),
|
||||
@@ -41,13 +41,12 @@ describe("Abstract Module Service Factory", () => {
|
||||
},
|
||||
}
|
||||
|
||||
const mainModelMock = class MainModelMock {}
|
||||
const otherModelMock1 = class OtherModelMock1 {}
|
||||
const otherModelMock2 = class OtherModelMock2 {}
|
||||
class MainModelMock {}
|
||||
class OtherModelMock1 {}
|
||||
class OtherModelMock2 {}
|
||||
|
||||
const abstractModuleService = abstractModuleServiceFactory<
|
||||
any,
|
||||
any,
|
||||
const abstractModuleService = MedusaService<
|
||||
MainModelMock,
|
||||
{
|
||||
OtherModelMock1: {
|
||||
dto: any
|
||||
@@ -60,22 +59,10 @@ describe("Abstract Module Service Factory", () => {
|
||||
plural: "OtherModelMock2s"
|
||||
}
|
||||
}
|
||||
>(
|
||||
mainModelMock,
|
||||
[
|
||||
{
|
||||
model: otherModelMock1,
|
||||
plural: "otherModelMock1s",
|
||||
singular: "otherModelMock1",
|
||||
},
|
||||
{
|
||||
model: otherModelMock2,
|
||||
plural: "otherModelMock2s",
|
||||
singular: "otherModelMock2",
|
||||
},
|
||||
]
|
||||
// Add more parameters as needed
|
||||
)
|
||||
>(MainModelMock, {
|
||||
OtherModelMock1,
|
||||
OtherModelMock2,
|
||||
})
|
||||
|
||||
describe("Main Model Methods", () => {
|
||||
let instance
|
||||
@@ -6,7 +6,7 @@ export * from "./loaders/mikro-orm-connection-loader-factory"
|
||||
export * from "./loaders/container-loader-factory"
|
||||
export * from "./create-pg-connection"
|
||||
export * from "./migration-scripts"
|
||||
export * from "./internal-module-service-factory"
|
||||
export * from "./abstract-module-service-factory"
|
||||
export * from "./medusa-internal-service"
|
||||
export * from "./medusa-service"
|
||||
export * from "./definition"
|
||||
export * from "./event-builder-factory"
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { asClass } from "awilix"
|
||||
import { internalModuleServiceFactory } from "../internal-module-service-factory"
|
||||
import { MedusaInternalService } from "../medusa-internal-service"
|
||||
import { lowerCaseFirst } from "../../common"
|
||||
import {
|
||||
MikroOrmBaseRepository,
|
||||
@@ -100,10 +100,7 @@ export function loadModuleServices({
|
||||
const finalService = moduleServicesMap.get(mappedServiceName)
|
||||
|
||||
if (!finalService) {
|
||||
moduleServicesMap.set(
|
||||
mappedServiceName,
|
||||
internalModuleServiceFactory(Model)
|
||||
)
|
||||
moduleServicesMap.set(mappedServiceName, MedusaInternalService(Model))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -33,20 +33,18 @@ type SelectorAndData = {
|
||||
data: any
|
||||
}
|
||||
|
||||
export function internalModuleServiceFactory<
|
||||
TContainer extends object = object
|
||||
>(
|
||||
export function MedusaInternalService<TContainer extends object = object>(
|
||||
model: any
|
||||
): {
|
||||
new <TEntity extends object = any>(
|
||||
container: TContainer
|
||||
): ModulesSdkTypes.InternalModuleService<TEntity, TContainer>
|
||||
): ModulesSdkTypes.IMedusaInternalService<TEntity, TContainer>
|
||||
} {
|
||||
const injectedRepositoryName = `${lowerCaseFirst(model.name)}Repository`
|
||||
const propertyRepositoryName = `__${injectedRepositoryName}__`
|
||||
|
||||
class AbstractService_<TEntity extends object>
|
||||
implements ModulesSdkTypes.InternalModuleService<TEntity, TContainer>
|
||||
implements ModulesSdkTypes.IMedusaInternalService<TEntity, TContainer>
|
||||
{
|
||||
readonly __container__: TContainer;
|
||||
[key: string]: any
|
||||
@@ -525,5 +523,5 @@ export function internalModuleServiceFactory<
|
||||
|
||||
return AbstractService_ as unknown as new <TEntity extends {}>(
|
||||
container: TContainer
|
||||
) => ModulesSdkTypes.InternalModuleService<TEntity, TContainer>
|
||||
) => ModulesSdkTypes.IMedusaInternalService<TEntity, TContainer>
|
||||
}
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
SoftDeleteReturn,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
MapToConfig,
|
||||
isString,
|
||||
kebabCase,
|
||||
lowerCaseFirst,
|
||||
mapObjectTo,
|
||||
MapToConfig,
|
||||
pluralize,
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
} from "./decorators"
|
||||
import { ModuleRegistrationName } from "./definition"
|
||||
|
||||
type BaseMethods =
|
||||
| "retrieve"
|
||||
@@ -49,68 +50,74 @@ const methods: BaseMethods[] = [...readMethods, ...writeMethods]
|
||||
|
||||
type ModelDTOConfig = {
|
||||
dto: object
|
||||
create?: object
|
||||
update?: object
|
||||
}
|
||||
type ModelDTOConfigRecord = Record<any, ModelDTOConfig>
|
||||
type ModelNamingConfig = {
|
||||
create?: any
|
||||
update?: any
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
singular?: string
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
plural?: string
|
||||
}
|
||||
|
||||
type ModelsConfigTemplate = {
|
||||
[ModelName: string]: ModelDTOConfig & ModelNamingConfig
|
||||
type EntitiesConfigTemplate = { [key: string]: ModelDTOConfig }
|
||||
|
||||
type ModelConfigurationToDto<T extends ModelConfiguration> =
|
||||
T extends abstract new (...args: any) => infer R
|
||||
? R
|
||||
: T extends { dto: infer DTO }
|
||||
? DTO
|
||||
: any
|
||||
|
||||
type ModelConfigurationsToConfigTemplate<
|
||||
T extends Record<string, ModelConfiguration>
|
||||
> = {
|
||||
[Key in keyof T as `${Capitalize<Key & string>}`]: {
|
||||
dto: ModelConfigurationToDto<T[Key]>
|
||||
create: any
|
||||
update: any
|
||||
}
|
||||
}
|
||||
|
||||
type ExtractSingularName<
|
||||
T extends Record<any, any>,
|
||||
K = keyof T
|
||||
> = T[K] extends { singular?: string } ? T[K]["singular"] : K
|
||||
|
||||
type CreateMethodName<
|
||||
TModelDTOConfig extends ModelDTOConfigRecord,
|
||||
TModelName = keyof TModelDTOConfig
|
||||
> = TModelDTOConfig[TModelName] extends { create?: object }
|
||||
? `create${ExtractPluralName<TModelDTOConfig, TModelName>}`
|
||||
: never
|
||||
|
||||
type UpdateMethodName<
|
||||
TModelDTOConfig extends ModelDTOConfigRecord,
|
||||
TModelName = keyof TModelDTOConfig
|
||||
> = TModelDTOConfig[TModelName] extends { update?: object }
|
||||
? `update${ExtractPluralName<TModelDTOConfig, TModelName>}`
|
||||
: never
|
||||
type ExtractSingularName<T extends Record<any, any>, K = keyof T> = Capitalize<
|
||||
T[K] extends { singular?: string } ? T[K]["singular"] & string : K & string
|
||||
>
|
||||
|
||||
type ExtractPluralName<T extends Record<any, any>, K = keyof T> = T[K] extends {
|
||||
plural?: string
|
||||
}
|
||||
? T[K]["plural"]
|
||||
? T[K]["plural"] & string
|
||||
: Pluralize<K & string>
|
||||
|
||||
type ModelConfiguration =
|
||||
| Constructor<any>
|
||||
| { singular?: string; plural?: string; model: Constructor<any> }
|
||||
// TODO: this will be removed in the follow up pr once the main entity concept will be removed
|
||||
type ModelConfiguration = Constructor<any> | ModelDTOConfig | any
|
||||
|
||||
export interface AbstractModuleServiceBase<TContainer, TMainModelDTO> {
|
||||
get __container__(): TContainer
|
||||
type ExtractMutationDtoOrAny<T> = T extends unknown ? any : T
|
||||
|
||||
export interface AbstractModuleServiceBase<TEntryEntityConfig> {
|
||||
new (container: Record<any, any>, ...args: any[]): this
|
||||
|
||||
get __container__(): Record<any, any>
|
||||
|
||||
retrieve(
|
||||
id: string,
|
||||
config?: FindConfig<any>,
|
||||
sharedContext?: Context
|
||||
): Promise<TMainModelDTO>
|
||||
): Promise<TEntryEntityConfig>
|
||||
|
||||
list(
|
||||
filters?: any,
|
||||
config?: FindConfig<any>,
|
||||
sharedContext?: Context
|
||||
): Promise<TMainModelDTO[]>
|
||||
): Promise<TEntryEntityConfig[]>
|
||||
|
||||
listAndCount(
|
||||
filters?: any,
|
||||
config?: FindConfig<any>,
|
||||
sharedContext?: Context
|
||||
): Promise<[TMainModelDTO[], number]>
|
||||
): Promise<[TEntryEntityConfig[], number]>
|
||||
|
||||
delete(
|
||||
primaryKeyValues: string | object | string[] | object[],
|
||||
@@ -131,56 +138,50 @@ export interface AbstractModuleServiceBase<TContainer, TMainModelDTO> {
|
||||
}
|
||||
|
||||
export type AbstractModuleService<
|
||||
TContainer,
|
||||
TMainModelDTO,
|
||||
TModelDTOConfig extends ModelsConfigTemplate
|
||||
> = AbstractModuleServiceBase<TContainer, TMainModelDTO> & {
|
||||
[TModelName in keyof TModelDTOConfig as `retrieve${ExtractSingularName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: (
|
||||
TEntryEntityConfig extends ModelConfiguration,
|
||||
TEntitiesDtoConfig extends EntitiesConfigTemplate
|
||||
> = AbstractModuleServiceBase<TEntryEntityConfig> & {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `retrieve${ExtractSingularName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: (
|
||||
id: string,
|
||||
config?: FindConfig<any>,
|
||||
sharedContext?: Context
|
||||
) => Promise<TModelDTOConfig[TModelName & string]["dto"]>
|
||||
) => Promise<TEntitiesDtoConfig[TEntityName]["dto"]>
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as `list${ExtractPluralName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: (
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `list${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: (
|
||||
filters?: any,
|
||||
config?: FindConfig<any>,
|
||||
sharedContext?: Context
|
||||
) => Promise<TModelDTOConfig[TModelName & string]["dto"][]>
|
||||
) => Promise<TEntitiesDtoConfig[TEntityName]["dto"][]>
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as `listAndCount${ExtractPluralName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `listAndCount${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(filters?: any, config?: FindConfig<any>, sharedContext?: Context): Promise<
|
||||
[TModelDTOConfig[TModelName & string]["dto"][], number]
|
||||
[TEntitiesDtoConfig[TEntityName]["dto"][], number]
|
||||
>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as `delete${ExtractPluralName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `delete${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(
|
||||
primaryKeyValues: string | object | string[] | object[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as `softDelete${ExtractPluralName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `softDelete${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
<TReturnableLinkableKeys extends string>(
|
||||
primaryKeyValues: string | object | string[] | object[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
@@ -188,11 +189,10 @@ export type AbstractModuleService<
|
||||
): Promise<Record<string, string[]> | void>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as `restore${ExtractPluralName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
> &
|
||||
string}`]: {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `restore${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
<TReturnableLinkableKeys extends string>(
|
||||
primaryKeyValues: string | object | string[] | object[],
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
@@ -200,45 +200,103 @@ export type AbstractModuleService<
|
||||
): Promise<Record<string, string[]> | void>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as CreateMethodName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
>]: {
|
||||
(
|
||||
data: TModelDTOConfig[TModelName]["create"][],
|
||||
sharedContext?: Context
|
||||
): Promise<TModelDTOConfig[TModelName]["dto"][]>
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(...args: any[]): Promise<any>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as CreateMethodName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
>]: {
|
||||
(
|
||||
data: TModelDTOConfig[TModelName]["create"],
|
||||
sharedContext?: Context
|
||||
): Promise<TModelDTOConfig[TModelName]["dto"]>
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(...args: any[]): Promise<any>
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Because of a bug, those methods were not made visible which now cause issues with the fix as our interface are not consistent with the expectations
|
||||
|
||||
// are not consistent accross modules
|
||||
/* & {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(data: any[], sharedContext?: Context): Promise<
|
||||
TEntitiesDtoConfig[TEntityName]["dto"][]
|
||||
>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as UpdateMethodName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
>]: {
|
||||
(
|
||||
data: TModelDTOConfig[TModelName]["update"][],
|
||||
sharedContext?: Context
|
||||
): Promise<TModelDTOConfig[TModelName]["dto"][]>
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `create${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(data: any, sharedContext?: Context): Promise<
|
||||
TEntitiesDtoConfig[TEntityName]["dto"][]
|
||||
>
|
||||
}
|
||||
} & {
|
||||
[TModelName in keyof TModelDTOConfig as UpdateMethodName<
|
||||
TModelDTOConfig,
|
||||
TModelName
|
||||
>]: {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(
|
||||
data: TModelDTOConfig[TModelName]["update"],
|
||||
data: TEntitiesDtoConfig[TEntityName]["update"][],
|
||||
sharedContext?: Context
|
||||
): Promise<TModelDTOConfig[TModelName]["dto"]>
|
||||
): Promise<TEntitiesDtoConfig[TEntityName]["dto"][]>
|
||||
}
|
||||
} & {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(
|
||||
data: TEntitiesDtoConfig[TEntityName]["update"],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntitiesDtoConfig[TEntityName]["dto"]>
|
||||
}
|
||||
} & {
|
||||
[TEntityName in keyof TEntitiesDtoConfig as `update${ExtractPluralName<
|
||||
TEntitiesDtoConfig,
|
||||
TEntityName
|
||||
>}`]: {
|
||||
(
|
||||
idOrdSelector: any,
|
||||
data: TEntitiesDtoConfig[TEntityName]["update"],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntitiesDtoConfig[TEntityName]["dto"][]>
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function buildMethodNamesFromModel(
|
||||
model: ModelConfiguration,
|
||||
suffixed: boolean = true
|
||||
): Record<string, string> {
|
||||
return methods.reduce((acc, method) => {
|
||||
let modelName: string = ""
|
||||
|
||||
if (method === "retrieve") {
|
||||
modelName =
|
||||
"singular" in model && model.singular
|
||||
? model.singular
|
||||
: (model as { name: string }).name
|
||||
} else {
|
||||
modelName =
|
||||
"plural" in model && model.plural
|
||||
? model.plural
|
||||
: pluralize((model as { name: string }).name)
|
||||
}
|
||||
|
||||
const methodName = suffixed
|
||||
? `${method}${upperCaseFirst(modelName)}`
|
||||
: method
|
||||
|
||||
return { ...acc, [method]: methodName }
|
||||
}, {})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +304,7 @@ export type AbstractModuleService<
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* const otherModels = new Set([
|
||||
* const entities = {
|
||||
* Currency,
|
||||
* Price,
|
||||
* PriceList,
|
||||
@@ -255,12 +313,10 @@ export type AbstractModuleService<
|
||||
* PriceRule,
|
||||
* PriceSetRuleType,
|
||||
* RuleType,
|
||||
* ])
|
||||
* }
|
||||
*
|
||||
* const AbstractModuleService = ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
* InjectedDependencies,
|
||||
* class MyService extends ModulesSdkUtils.MedusaService<
|
||||
* PricingTypes.PriceSetDTO,
|
||||
* // The configuration of each entity also accept singular/plural properties, if not provided then it is using english pluralization
|
||||
* {
|
||||
* Currency: { dto: PricingTypes.CurrencyDTO }
|
||||
* Price: { dto: PricingTypes.PriceDTO }
|
||||
@@ -269,61 +325,55 @@ export type AbstractModuleService<
|
||||
* PriceList: { dto: PricingTypes.PriceListDTO }
|
||||
* PriceListRule: { dto: PricingTypes.PriceListRuleDTO }
|
||||
* }
|
||||
* >(PriceSet, [...otherModels], entityNameToLinkableKeysMap)
|
||||
* >(PriceSet, entities, entityNameToLinkableKeysMap) {}
|
||||
*
|
||||
* @param mainModel
|
||||
* @param otherModels
|
||||
* @example
|
||||
*
|
||||
* // Here the DTO's and names will be inferred from the arguments
|
||||
*
|
||||
* const entities = {
|
||||
* Currency,
|
||||
* Price,
|
||||
* PriceList,
|
||||
* PriceListRule,
|
||||
* PriceListRuleValue,
|
||||
* PriceRule,
|
||||
* PriceSetRuleType,
|
||||
* RuleType,
|
||||
* }
|
||||
*
|
||||
* class MyService extends ModulesSdkUtils.MedusaService(PriceSet, entities, entityNameToLinkableKeysMap) {}
|
||||
*
|
||||
* @param entryEntity
|
||||
* @param entities
|
||||
* @param entityNameToLinkableKeysMap
|
||||
*/
|
||||
export function abstractModuleServiceFactory<
|
||||
TContainer,
|
||||
TMainModelDTO,
|
||||
ModelsConfig extends ModelsConfigTemplate
|
||||
export function MedusaService<
|
||||
TEntryEntityConfig extends ModelConfiguration = ModelConfiguration,
|
||||
EntitiesConfig extends EntitiesConfigTemplate = { __empty: any },
|
||||
TEntities extends Record<string, ModelConfiguration> = Record<
|
||||
string,
|
||||
ModelConfiguration
|
||||
>
|
||||
>(
|
||||
mainModel: Constructor<any>,
|
||||
otherModels: ModelConfiguration[],
|
||||
entryEntity: (TEntryEntityConfig & { name: string }) | Constructor<any>,
|
||||
entities: TEntities,
|
||||
entityNameToLinkableKeysMap: MapToConfig = {}
|
||||
): {
|
||||
new (container: TContainer): AbstractModuleService<
|
||||
TContainer,
|
||||
TMainModelDTO,
|
||||
ModelsConfig
|
||||
new (...args: any[]): AbstractModuleService<
|
||||
ModelConfigurationToDto<TEntryEntityConfig>,
|
||||
EntitiesConfig extends { __empty: any }
|
||||
? ModelConfigurationsToConfigTemplate<TEntities>
|
||||
: EntitiesConfig
|
||||
>
|
||||
} {
|
||||
const buildMethodNamesFromModel = (
|
||||
model: ModelConfiguration,
|
||||
suffixed: boolean = true
|
||||
): Record<string, string> => {
|
||||
return methods.reduce((acc, method) => {
|
||||
let modelName: string = ""
|
||||
|
||||
if (method === "retrieve") {
|
||||
modelName =
|
||||
"singular" in model && model.singular
|
||||
? model.singular
|
||||
: (model as Constructor<any>).name
|
||||
} else {
|
||||
modelName =
|
||||
"plural" in model && model.plural
|
||||
? model.plural
|
||||
: pluralize((model as Constructor<any>).name)
|
||||
}
|
||||
|
||||
const methodName = suffixed
|
||||
? `${method}${upperCaseFirst(modelName)}`
|
||||
: method
|
||||
|
||||
return { ...acc, [method]: methodName }
|
||||
}, {})
|
||||
}
|
||||
|
||||
const buildAndAssignMethodImpl = function (
|
||||
klassPrototype: any,
|
||||
method: string,
|
||||
methodName: string,
|
||||
model: Constructor<any>
|
||||
modelName: string
|
||||
): void {
|
||||
const serviceRegistrationName = `${lowerCaseFirst(model.name)}Service`
|
||||
const serviceRegistrationName = `${lowerCaseFirst(modelName)}Service`
|
||||
|
||||
const applyMethod = function (impl: Function, contextIndex) {
|
||||
klassPrototype[methodName] = impl
|
||||
@@ -465,7 +515,7 @@ export function abstractModuleServiceFactory<
|
||||
|
||||
await this.eventBusModuleService_?.emit(
|
||||
primaryKeyValues_.map((primaryKeyValue) => ({
|
||||
eventName: `${kebabCase(model.name)}.deleted`,
|
||||
eventName: `${kebabCase(modelName)}.deleted`,
|
||||
data: isString(primaryKeyValue)
|
||||
? { id: primaryKeyValue }
|
||||
: primaryKeyValue,
|
||||
@@ -500,7 +550,7 @@ export function abstractModuleServiceFactory<
|
||||
|
||||
await this.eventBusModuleService_?.emit(
|
||||
softDeletedEntities.map(({ id }) => ({
|
||||
eventName: `${kebabCase(model.name)}.deleted`,
|
||||
eventName: `${kebabCase(modelName)}.deleted`,
|
||||
metadata: { source: "", action: "", object: "" },
|
||||
data: { id },
|
||||
}))
|
||||
@@ -558,19 +608,19 @@ export function abstractModuleServiceFactory<
|
||||
}
|
||||
|
||||
class AbstractModuleService_ {
|
||||
readonly __container__: Record<string, any>
|
||||
readonly __container__: Record<any, any>
|
||||
readonly baseRepository_: RepositoryService
|
||||
readonly eventBusModuleService_: IEventBusModuleService;
|
||||
|
||||
[key: string]: any
|
||||
|
||||
constructor(container: Record<string, any>) {
|
||||
constructor(container: Record<any, any>) {
|
||||
this.__container__ = container
|
||||
this.baseRepository_ = container.baseRepository
|
||||
|
||||
const hasEventBusModuleService = Object.keys(this.__container__).find(
|
||||
// TODO: Should use ModuleRegistrationName.EVENT_BUS but it would require to move it to the utils package to prevent circular dependencies
|
||||
(key) => key === "eventBusModuleService"
|
||||
(key) => key === ModuleRegistrationName.EVENT_BUS
|
||||
)
|
||||
|
||||
this.eventBusModuleService_ = hasEventBusModuleService
|
||||
@@ -592,18 +642,18 @@ export function abstractModuleServiceFactory<
|
||||
}
|
||||
}
|
||||
|
||||
const mainModelMethods = buildMethodNamesFromModel(mainModel, false)
|
||||
const entryEntityMethods = buildMethodNamesFromModel(entryEntity, false)
|
||||
|
||||
/**
|
||||
* Build the main retrieve/list/listAndCount/delete/softDelete/restore methods for the main model
|
||||
*/
|
||||
|
||||
for (let [method, methodName] of Object.entries(mainModelMethods)) {
|
||||
for (let [method, methodName] of Object.entries(entryEntityMethods)) {
|
||||
buildAndAssignMethodImpl(
|
||||
AbstractModuleService_.prototype,
|
||||
method,
|
||||
methodName,
|
||||
mainModel
|
||||
entryEntity.name
|
||||
)
|
||||
}
|
||||
|
||||
@@ -611,22 +661,26 @@ export function abstractModuleServiceFactory<
|
||||
* Build the retrieve/list/listAndCount/delete/softDelete/restore methods for all the other models
|
||||
*/
|
||||
|
||||
const otherModelsMethods: [ModelConfiguration, Record<string, string>][] =
|
||||
otherModels.map((model) => [model, buildMethodNamesFromModel(model)])
|
||||
const entitiesMethods: [
|
||||
string,
|
||||
ModelConfiguration,
|
||||
Record<string, string>
|
||||
][] = Object.entries(entities).map(([name, config]) => [
|
||||
name,
|
||||
config,
|
||||
buildMethodNamesFromModel(config),
|
||||
])
|
||||
|
||||
for (let [model, modelsMethods] of otherModelsMethods) {
|
||||
for (let [modelName, model, modelsMethods] of entitiesMethods) {
|
||||
Object.entries(modelsMethods).forEach(([method, methodName]) => {
|
||||
model = "model" in model ? model.model : model
|
||||
buildAndAssignMethodImpl(
|
||||
AbstractModuleService_.prototype,
|
||||
method,
|
||||
methodName,
|
||||
model
|
||||
modelName
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return AbstractModuleService_ as unknown as new (
|
||||
container: TContainer
|
||||
) => AbstractModuleService<TContainer, TMainModelDTO, ModelsConfig>
|
||||
return AbstractModuleService_ as any
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import crypto from "crypto"
|
||||
import util from "util"
|
||||
import {
|
||||
ApiKeyTypes,
|
||||
Context,
|
||||
DAL,
|
||||
ApiKeyTypes,
|
||||
FilterableApiKeyProps,
|
||||
FindConfig,
|
||||
IApiKeyModuleService,
|
||||
ModulesSdkTypes,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
FindConfig,
|
||||
FilterableApiKeyProps,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { ApiKey } from "@models"
|
||||
@@ -23,35 +23,32 @@ import {
|
||||
ApiKeyType,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isObject,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
isObject,
|
||||
isString,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
const scrypt = util.promisify(crypto.scrypt)
|
||||
|
||||
const generateMethodForModels = []
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
apiKeyService: ModulesSdkTypes.InternalModuleService<any>
|
||||
apiKeyService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class ApiKeyModuleService<TEntity extends ApiKey = ApiKey>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
ApiKeyTypes.ApiKeyDTO,
|
||||
{
|
||||
ApiKey: { dto: ApiKeyTypes.ApiKeyDTO }
|
||||
}
|
||||
>(ApiKey, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
>(ApiKey, {}, entityNameToLinkableKeysMap)
|
||||
implements IApiKeyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly apiKeyService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly apiKeyService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, apiKeyService }: InjectedDependencies,
|
||||
|
||||
@@ -21,23 +21,21 @@ import {
|
||||
ModulesSdkUtils,
|
||||
} from "@medusajs/utils"
|
||||
import AuthProviderService from "./auth-provider"
|
||||
import { populate } from "dotenv"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
authIdentityService: ModulesSdkTypes.InternalModuleService<any>
|
||||
providerIdentityService: ModulesSdkTypes.InternalModuleService<any>
|
||||
authIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
authProviderService: AuthProviderService
|
||||
}
|
||||
|
||||
const generateMethodForModels = [AuthIdentity, ProviderIdentity]
|
||||
const generateMethodForModels = { AuthIdentity, ProviderIdentity }
|
||||
|
||||
export default class AuthModuleService<
|
||||
TAuthIdentity extends AuthIdentity = AuthIdentity,
|
||||
TProviderIdentity extends ProviderIdentity = ProviderIdentity
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
AuthTypes.AuthIdentityDTO,
|
||||
{
|
||||
AuthIdentity: { dto: AuthTypes.AuthIdentityDTO }
|
||||
@@ -47,8 +45,8 @@ export default class AuthModuleService<
|
||||
implements AuthTypes.IAuthModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected authIdentityService_: ModulesSdkTypes.InternalModuleService<TAuthIdentity>
|
||||
protected providerIdentityService_: ModulesSdkTypes.InternalModuleService<TProviderIdentity>
|
||||
protected authIdentityService_: ModulesSdkTypes.IMedusaInternalService<TAuthIdentity>
|
||||
protected providerIdentityService_: ModulesSdkTypes.IMedusaInternalService<TProviderIdentity>
|
||||
protected readonly authProviderService_: AuthProviderService
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -10,16 +10,16 @@ import {
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
createRawPropertiesFromBigNumber,
|
||||
decorateCartTotals,
|
||||
deduplicate,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isObject,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
Address,
|
||||
@@ -43,17 +43,17 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
cartService: ModulesSdkTypes.InternalModuleService<any>
|
||||
addressService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
cartService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
addressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
Address,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
@@ -61,7 +61,7 @@ const generateMethodForModels = [
|
||||
ShippingMethod,
|
||||
ShippingMethodAdjustment,
|
||||
ShippingMethodTaxLine,
|
||||
]
|
||||
}
|
||||
|
||||
export default class CartModuleService<
|
||||
TCart extends Cart = Cart,
|
||||
@@ -73,8 +73,7 @@ export default class CartModuleService<
|
||||
TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine,
|
||||
TShippingMethod extends ShippingMethod = ShippingMethod
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CartTypes.CartDTO,
|
||||
{
|
||||
Address: { dto: CartTypes.CartAddressDTO }
|
||||
@@ -89,14 +88,14 @@ export default class CartModuleService<
|
||||
implements ICartModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected cartService_: ModulesSdkTypes.InternalModuleService<TCart>
|
||||
protected addressService_: ModulesSdkTypes.InternalModuleService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.InternalModuleService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.InternalModuleService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>
|
||||
protected cartService_: ModulesSdkTypes.IMedusaInternalService<TCart>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodTaxLine>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -449,6 +448,7 @@ export default class CartModuleService<
|
||||
return await this.lineItemService_.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateLineItems(
|
||||
data: CartTypes.UpdateLineItemWithSelectorDTO[]
|
||||
): Promise<CartTypes.CartLineItemDTO[]>
|
||||
@@ -541,6 +541,7 @@ export default class CartModuleService<
|
||||
return await this.lineItemService_.update(toUpdate, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createAddresses(
|
||||
data: CartTypes.CreateAddressDTO,
|
||||
sharedContext?: Context
|
||||
@@ -577,6 +578,7 @@ export default class CartModuleService<
|
||||
return await this.addressService_.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateAddresses(
|
||||
data: CartTypes.UpdateAddressDTO,
|
||||
sharedContext?: Context
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async ({
|
||||
const logger =
|
||||
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
const { currencyService_ } = container.resolve<{
|
||||
currencyService_: ModulesSdkTypes.InternalModuleService<Currency>
|
||||
currencyService_: ModulesSdkTypes.IMedusaInternalService<Currency>
|
||||
}>(ModuleRegistrationName.CURRENCY)
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
Context,
|
||||
CurrencyTypes,
|
||||
DAL,
|
||||
FilterableCurrencyProps,
|
||||
FindConfig,
|
||||
ICurrencyModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
ICurrencyModuleService,
|
||||
CurrencyTypes,
|
||||
Context,
|
||||
FindConfig,
|
||||
FilterableCurrencyProps,
|
||||
BaseFilterable,
|
||||
} from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
|
||||
import { Currency } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
const generateMethodForModels = []
|
||||
const generateMethodForModels = {}
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
currencyService: ModulesSdkTypes.InternalModuleService<any>
|
||||
currencyService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class CurrencyModuleService<TEntity extends Currency = Currency>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CurrencyTypes.CurrencyDTO,
|
||||
{
|
||||
Currency: { dto: CurrencyTypes.CurrencyDTO }
|
||||
@@ -33,7 +32,7 @@ export default class CurrencyModuleService<TEntity extends Currency = Currency>
|
||||
implements ICurrencyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly currencyService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, currencyService }: InjectedDependencies,
|
||||
|
||||
@@ -27,17 +27,17 @@ import { EntityManager } from "@mikro-orm/core"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
customerService: ModulesSdkTypes.InternalModuleService<any>
|
||||
addressService: ModulesSdkTypes.InternalModuleService<any>
|
||||
customerGroupService: ModulesSdkTypes.InternalModuleService<any>
|
||||
customerGroupCustomerService: ModulesSdkTypes.InternalModuleService<any>
|
||||
customerService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
addressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
customerGroupService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
customerGroupCustomerService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
{ model: Address, singular: "Address", plural: "Addresses" },
|
||||
const generateMethodForModels = {
|
||||
Address: { singular: "Address", plural: "Addresses" },
|
||||
CustomerGroup,
|
||||
CustomerGroupCustomer,
|
||||
]
|
||||
}
|
||||
|
||||
export default class CustomerModuleService<
|
||||
TAddress extends Address = Address,
|
||||
@@ -45,8 +45,7 @@ export default class CustomerModuleService<
|
||||
TCustomerGroup extends CustomerGroup = CustomerGroup,
|
||||
TCustomerGroupCustomer extends CustomerGroupCustomer = CustomerGroupCustomer
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CustomerDTO,
|
||||
{
|
||||
Address: { dto: any }
|
||||
@@ -57,10 +56,10 @@ export default class CustomerModuleService<
|
||||
implements ICustomerModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected customerService_: ModulesSdkTypes.InternalModuleService<TCustomer>
|
||||
protected addressService_: ModulesSdkTypes.InternalModuleService<TAddress>
|
||||
protected customerGroupService_: ModulesSdkTypes.InternalModuleService<TCustomerGroup>
|
||||
protected customerGroupCustomerService_: ModulesSdkTypes.InternalModuleService<TCustomerGroupCustomer>
|
||||
protected customerService_: ModulesSdkTypes.IMedusaInternalService<TCustomer>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||
protected customerGroupService_: ModulesSdkTypes.IMedusaInternalService<TCustomerGroup>
|
||||
protected customerGroupCustomerService_: ModulesSdkTypes.IMedusaInternalService<TCustomerGroupCustomer>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -233,6 +232,7 @@ export default class CustomerModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateCustomerGroups(
|
||||
groupId: string,
|
||||
data: CustomerTypes.CustomerGroupUpdatableFields,
|
||||
@@ -372,6 +372,7 @@ export default class CustomerModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateAddresses(
|
||||
addressId: string,
|
||||
data: CustomerTypes.UpdateCustomerAddressDTO,
|
||||
|
||||
@@ -66,7 +66,7 @@ async function syncDatabaseProviders({ container }) {
|
||||
container.resolve(FulfillmentIdentifiersRegistrationName) ?? []
|
||||
).filter(Boolean)
|
||||
|
||||
const providerService: ModulesSdkTypes.InternalModuleService<any> =
|
||||
const providerService: ModulesSdkTypes.IMedusaInternalService<any> =
|
||||
container.resolve(providerServiceRegistrationKey)
|
||||
|
||||
const providers = await providerService.list({})
|
||||
|
||||
@@ -14,18 +14,18 @@ import {
|
||||
UpdateServiceZoneDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
EmitEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
arrayDifference,
|
||||
deepEqualObj,
|
||||
EmitEvents,
|
||||
getSetDifference,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
isPresent,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
@@ -52,7 +52,7 @@ import { UpdateShippingOptionsInput } from "../types/service"
|
||||
import { buildCreatedShippingOptionEvents } from "../utils/events"
|
||||
import FulfillmentProviderService from "./fulfillment-provider"
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
ServiceZone,
|
||||
ShippingOption,
|
||||
GeoZone,
|
||||
@@ -61,19 +61,19 @@ const generateMethodForModels = [
|
||||
ShippingOptionType,
|
||||
FulfillmentProvider,
|
||||
// Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose8
|
||||
]
|
||||
}
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
fulfillmentSetService: ModulesSdkTypes.InternalModuleService<any>
|
||||
serviceZoneService: ModulesSdkTypes.InternalModuleService<any>
|
||||
geoZoneService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingProfileService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingOptionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingOptionRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingOptionTypeService: ModulesSdkTypes.InternalModuleService<any>
|
||||
fulfillmentSetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
serviceZoneService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
geoZoneService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingProfileService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingOptionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingOptionRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
fulfillmentProviderService: FulfillmentProviderService
|
||||
fulfillmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
fulfillmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class FulfillmentModuleService<
|
||||
@@ -86,8 +86,7 @@ export default class FulfillmentModuleService<
|
||||
TSippingOptionTypeEntity extends ShippingOptionType = ShippingOptionType,
|
||||
TFulfillmentEntity extends Fulfillment = Fulfillment
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
FulfillmentTypes.FulfillmentSetDTO,
|
||||
{
|
||||
FulfillmentSet: { dto: FulfillmentTypes.FulfillmentSetDTO }
|
||||
@@ -103,15 +102,15 @@ export default class FulfillmentModuleService<
|
||||
implements IFulfillmentModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly fulfillmentSetService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly serviceZoneService_: ModulesSdkTypes.InternalModuleService<TServiceZoneEntity>
|
||||
protected readonly geoZoneService_: ModulesSdkTypes.InternalModuleService<TGeoZoneEntity>
|
||||
protected readonly shippingProfileService_: ModulesSdkTypes.InternalModuleService<TShippingProfileEntity>
|
||||
protected readonly shippingOptionService_: ModulesSdkTypes.InternalModuleService<TShippingOptionEntity>
|
||||
protected readonly shippingOptionRuleService_: ModulesSdkTypes.InternalModuleService<TShippingOptionRuleEntity>
|
||||
protected readonly shippingOptionTypeService_: ModulesSdkTypes.InternalModuleService<TSippingOptionTypeEntity>
|
||||
protected readonly fulfillmentSetService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
protected readonly serviceZoneService_: ModulesSdkTypes.IMedusaInternalService<TServiceZoneEntity>
|
||||
protected readonly geoZoneService_: ModulesSdkTypes.IMedusaInternalService<TGeoZoneEntity>
|
||||
protected readonly shippingProfileService_: ModulesSdkTypes.IMedusaInternalService<TShippingProfileEntity>
|
||||
protected readonly shippingOptionService_: ModulesSdkTypes.IMedusaInternalService<TShippingOptionEntity>
|
||||
protected readonly shippingOptionRuleService_: ModulesSdkTypes.IMedusaInternalService<TShippingOptionRuleEntity>
|
||||
protected readonly shippingOptionTypeService_: ModulesSdkTypes.IMedusaInternalService<TSippingOptionTypeEntity>
|
||||
protected readonly fulfillmentProviderService_: FulfillmentProviderService
|
||||
protected readonly fulfillmentService_: ModulesSdkTypes.InternalModuleService<TFulfillmentEntity>
|
||||
protected readonly fulfillmentService_: ModulesSdkTypes.IMedusaInternalService<TFulfillmentEntity>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -325,6 +324,7 @@ export default class FulfillmentModuleService<
|
||||
return createdFulfillmentSets
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createServiceZones(
|
||||
data: FulfillmentTypes.CreateServiceZoneDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -388,6 +388,7 @@ export default class FulfillmentModuleService<
|
||||
return createdServiceZones
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createShippingOptions(
|
||||
data: FulfillmentTypes.CreateShippingOptionDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -448,6 +449,7 @@ export default class FulfillmentModuleService<
|
||||
return createdSO
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createShippingProfiles(
|
||||
data: FulfillmentTypes.CreateShippingProfileDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -501,6 +503,7 @@ export default class FulfillmentModuleService<
|
||||
return await this.shippingProfileService_.create(data_, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createGeoZones(
|
||||
data: FulfillmentTypes.CreateGeoZoneDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -537,6 +540,7 @@ export default class FulfillmentModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createShippingOptionRules(
|
||||
data: FulfillmentTypes.CreateShippingOptionRuleDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -924,6 +928,7 @@ export default class FulfillmentModuleService<
|
||||
: updatedFulfillmentSets[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateServiceZones(
|
||||
id: string,
|
||||
data: FulfillmentTypes.UpdateServiceZoneDTO,
|
||||
@@ -1223,6 +1228,7 @@ export default class FulfillmentModuleService<
|
||||
return [...created, ...updated]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateShippingOptions(
|
||||
id: string,
|
||||
data: FulfillmentTypes.UpdateShippingOptionDTO,
|
||||
@@ -1540,6 +1546,7 @@ export default class FulfillmentModuleService<
|
||||
return [...created, ...updated]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateShippingProfiles(
|
||||
selector: FulfillmentTypes.FilterableShippingProfileProps,
|
||||
data: FulfillmentTypes.UpdateShippingProfileDTO,
|
||||
@@ -1643,6 +1650,7 @@ export default class FulfillmentModuleService<
|
||||
return Array.isArray(data) ? allProfiles : allProfiles[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateGeoZones(
|
||||
data: FulfillmentTypes.UpdateGeoZoneDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -1685,6 +1693,7 @@ export default class FulfillmentModuleService<
|
||||
return Array.isArray(data) ? serialized : serialized[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateShippingOptionRules(
|
||||
data: FulfillmentTypes.UpdateShippingOptionRuleDTO[],
|
||||
sharedContext?: Context
|
||||
|
||||
@@ -14,7 +14,7 @@ type InjectedDependencies = {
|
||||
|
||||
// TODO rework DTO's
|
||||
|
||||
export default class FulfillmentProviderService extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
FulfillmentProvider
|
||||
) {
|
||||
protected readonly fulfillmentProviderRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -10,7 +10,7 @@ type InjectedDependencies = {
|
||||
|
||||
export default class InventoryLevelService<
|
||||
TEntity extends InventoryLevel = InventoryLevel
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
InventoryLevel
|
||||
)<TEntity> {
|
||||
protected readonly inventoryLevelRepository: InventoryLevelRepository
|
||||
|
||||
@@ -30,20 +30,23 @@ import InventoryLevelService from "./inventory-level"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
inventoryItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
inventoryItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
inventoryLevelService: InventoryLevelService<any>
|
||||
reservationItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
reservationItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [InventoryItem, InventoryLevel, ReservationItem]
|
||||
const generateMethodForModels = {
|
||||
InventoryItem,
|
||||
InventoryLevel,
|
||||
ReservationItem,
|
||||
}
|
||||
|
||||
export default class InventoryModuleService<
|
||||
TInventoryItem extends InventoryItem = InventoryItem,
|
||||
TInventoryLevel extends InventoryLevel = InventoryLevel,
|
||||
TReservationItem extends ReservationItem = ReservationItem
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
InventoryNext.InventoryItemDTO,
|
||||
{
|
||||
InventoryItem: {
|
||||
@@ -61,8 +64,8 @@ export default class InventoryModuleService<
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
protected readonly inventoryItemService_: ModulesSdkTypes.InternalModuleService<TInventoryItem>
|
||||
protected readonly reservationItemService_: ModulesSdkTypes.InternalModuleService<TReservationItem>
|
||||
protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService<TInventoryItem>
|
||||
protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService<TReservationItem>
|
||||
protected readonly inventoryLevelService_: InventoryLevelService<TInventoryLevel>
|
||||
|
||||
constructor(
|
||||
@@ -209,6 +212,7 @@ export default class InventoryModuleService<
|
||||
await promiseAll(checkLevels)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createReservationItems(
|
||||
input: InventoryNext.CreateReservationItemInput[],
|
||||
context?: Context
|
||||
@@ -365,6 +369,7 @@ export default class InventoryModuleService<
|
||||
return await this.inventoryItemService_.create(input)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createInventoryLevels(
|
||||
input: InventoryNext.CreateInventoryLevelInput,
|
||||
context?: Context
|
||||
@@ -537,6 +542,7 @@ export default class InventoryModuleService<
|
||||
return await this.inventoryLevelService_.delete(inventoryLevel.id, context)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateInventoryLevels(
|
||||
updates: InventoryTypes.BulkUpdateInventoryLevelInput[],
|
||||
context?: Context
|
||||
@@ -623,6 +629,7 @@ export default class InventoryModuleService<
|
||||
* @param context
|
||||
* @return The updated inventory level
|
||||
*/
|
||||
// @ts-ignore
|
||||
async updateReservationItems(
|
||||
input: InventoryNext.UpdateReservationItemInput[],
|
||||
context?: Context
|
||||
|
||||
@@ -62,7 +62,7 @@ async function syncDatabaseProviders({
|
||||
const providerServiceRegistrationKey = lowerCaseFirst(
|
||||
NotificationProviderService.name
|
||||
)
|
||||
const providerService: ModulesSdkTypes.InternalModuleService<NotificationProvider> =
|
||||
const providerService: ModulesSdkTypes.IMedusaInternalService<NotificationProvider> =
|
||||
container.resolve(providerServiceRegistrationKey)
|
||||
|
||||
const logger = container.resolve(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
NotificationTypes,
|
||||
INotificationModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
NotificationTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
promiseAll,
|
||||
MedusaError,
|
||||
} from "@medusajs/utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import NotificationProviderService from "./notification-provider"
|
||||
import { NotificationModel, NotificationProvider } from "@models"
|
||||
|
||||
const generateMethodForModels = [NotificationProvider]
|
||||
const generateMethodForModels = { NotificationProvider }
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
notificationModelService: ModulesSdkTypes.InternalModuleService<any>
|
||||
notificationModelService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
notificationProviderService: NotificationProviderService
|
||||
}
|
||||
|
||||
export default class NotificationModuleService<
|
||||
TEntity extends NotificationModel = NotificationModel
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
NotificationTypes.NotificationDTO,
|
||||
{
|
||||
NotificationProvider: { dto: NotificationTypes.NotificationProviderDTO }
|
||||
@@ -40,7 +39,7 @@ export default class NotificationModuleService<
|
||||
implements INotificationModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly notificationService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly notificationService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
protected readonly notificationProviderService_: NotificationProviderService
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constructor, DAL, NotificationTypes } from "@medusajs/types"
|
||||
import { ModulesSdkUtils, MedusaError } from "@medusajs/utils"
|
||||
import { DAL, NotificationTypes } from "@medusajs/types"
|
||||
import { MedusaError, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { NotificationProvider } from "@models"
|
||||
import { NotificationProviderRegistrationPrefix } from "@types"
|
||||
|
||||
@@ -10,7 +10,7 @@ type InjectedDependencies = {
|
||||
]: NotificationTypes.INotificationProvider
|
||||
}
|
||||
|
||||
export default class NotificationProviderService extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
NotificationProvider
|
||||
) {
|
||||
protected readonly notificationProviderRepository_: DAL.RepositoryService<NotificationProvider>
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
RepositoryService,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
deduplicate,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
deduplicate,
|
||||
} from "@medusajs/utils"
|
||||
import { OrderChange } from "@models"
|
||||
import { OrderChangeStatus } from "@types"
|
||||
@@ -22,7 +22,7 @@ type InjectedDependencies = {
|
||||
|
||||
export default class OrderChangeService<
|
||||
TEntity extends OrderChange = OrderChange
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
OrderChange
|
||||
)<TEntity> {
|
||||
protected readonly orderChangeRepository_: RepositoryService<TEntity>
|
||||
|
||||
@@ -76,24 +76,24 @@ import OrderService from "./order-service"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
orderService: OrderService<any>
|
||||
addressService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
transactionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
addressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
transactionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
orderChangeService: OrderChangeService<any>
|
||||
orderChangeActionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
orderItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
orderSummaryService: ModulesSdkTypes.InternalModuleService<any>
|
||||
orderShippingMethodService: ModulesSdkTypes.InternalModuleService<any>
|
||||
returnReasonService: ModulesSdkTypes.InternalModuleService<any>
|
||||
returnService: ModulesSdkTypes.InternalModuleService<any>
|
||||
orderChangeActionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
orderItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
orderSummaryService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
orderShippingMethodService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
returnReasonService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
returnService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
Address,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
@@ -109,7 +109,7 @@ const generateMethodForModels = [
|
||||
OrderShippingMethod,
|
||||
ReturnReason,
|
||||
Return,
|
||||
]
|
||||
}
|
||||
|
||||
export default class OrderModuleService<
|
||||
TOrder extends Order = Order,
|
||||
@@ -129,8 +129,7 @@ export default class OrderModuleService<
|
||||
TReturnReason extends ReturnReason = ReturnReason,
|
||||
TReturn extends Return = Return
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
OrderTypes.OrderDTO,
|
||||
{
|
||||
Address: { dto: OrderTypes.OrderAddressDTO }
|
||||
@@ -156,21 +155,21 @@ export default class OrderModuleService<
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected orderService_: OrderService<TOrder>
|
||||
protected addressService_: ModulesSdkTypes.InternalModuleService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.InternalModuleService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.InternalModuleService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>
|
||||
protected transactionService_: ModulesSdkTypes.InternalModuleService<TTransaction>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodTaxLine>
|
||||
protected transactionService_: ModulesSdkTypes.IMedusaInternalService<TTransaction>
|
||||
protected orderChangeService_: OrderChangeService<TOrderChange>
|
||||
protected orderChangeActionService_: ModulesSdkTypes.InternalModuleService<TOrderChangeAction>
|
||||
protected orderItemService_: ModulesSdkTypes.InternalModuleService<TOrderItem>
|
||||
protected orderSummaryService_: ModulesSdkTypes.InternalModuleService<TOrderSummary>
|
||||
protected orderShippingMethodService_: ModulesSdkTypes.InternalModuleService<TOrderShippingMethod>
|
||||
protected returnReasonService_: ModulesSdkTypes.InternalModuleService<TReturnReason>
|
||||
protected returnService_: ModulesSdkTypes.InternalModuleService<TReturn>
|
||||
protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService<TOrderChangeAction>
|
||||
protected orderItemService_: ModulesSdkTypes.IMedusaInternalService<TOrderItem>
|
||||
protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService<TOrderSummary>
|
||||
protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService<TOrderShippingMethod>
|
||||
protected returnReasonService_: ModulesSdkTypes.IMedusaInternalService<TReturnReason>
|
||||
protected returnService_: ModulesSdkTypes.IMedusaInternalService<TReturn>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -553,6 +552,7 @@ export default class OrderModuleService<
|
||||
return result
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createLineItems(
|
||||
data: OrderTypes.CreateOrderLineItemForOrderDTO
|
||||
): Promise<OrderTypes.OrderLineItemDTO[]>
|
||||
@@ -670,6 +670,7 @@ export default class OrderModuleService<
|
||||
return lineItems
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateLineItems(
|
||||
data: OrderTypes.UpdateOrderLineItemWithSelectorDTO[]
|
||||
): Promise<OrderTypes.OrderLineItemDTO[]>
|
||||
@@ -883,6 +884,7 @@ export default class OrderModuleService<
|
||||
return await this.orderItemService_.update(toUpdate, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createAddresses(
|
||||
data: OrderTypes.CreateOrderAddressDTO,
|
||||
sharedContext?: Context
|
||||
@@ -919,6 +921,7 @@ export default class OrderModuleService<
|
||||
return await this.addressService_.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateAddresses(
|
||||
data: OrderTypes.UpdateOrderAddressDTO,
|
||||
sharedContext?: Context
|
||||
@@ -955,6 +958,7 @@ export default class OrderModuleService<
|
||||
return await this.addressService_.update(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createShippingMethods(
|
||||
data: OrderTypes.CreateOrderShippingMethodDTO
|
||||
): Promise<OrderTypes.OrderShippingMethodDTO>
|
||||
@@ -1059,6 +1063,7 @@ export default class OrderModuleService<
|
||||
return sm.map((s) => s.shipping_method)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createLineItemAdjustments(
|
||||
adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[]
|
||||
): Promise<OrderTypes.OrderLineItemAdjustmentDTO[]>
|
||||
@@ -1228,6 +1233,7 @@ export default class OrderModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createShippingMethodAdjustments(
|
||||
adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[]
|
||||
): Promise<OrderTypes.OrderShippingMethodAdjustmentDTO[]>
|
||||
@@ -1302,6 +1308,7 @@ export default class OrderModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createLineItemTaxLines(
|
||||
taxLines: OrderTypes.CreateOrderLineItemTaxLineDTO[]
|
||||
): Promise<OrderTypes.OrderLineItemTaxLineDTO[]>
|
||||
@@ -1412,6 +1419,7 @@ export default class OrderModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createShippingMethodTaxLines(
|
||||
taxLines: OrderTypes.CreateOrderShippingMethodTaxLineDTO[]
|
||||
): Promise<OrderTypes.OrderShippingMethodTaxLineDTO[]>
|
||||
@@ -2319,6 +2327,7 @@ export default class OrderModuleService<
|
||||
await this.orderSummaryService_.update(summaries, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createReturnReasons(
|
||||
transactionData: OrderTypes.CreateOrderReturnReasonDTO,
|
||||
sharedContext?: Context
|
||||
@@ -2352,6 +2361,7 @@ export default class OrderModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateReturnReasons(
|
||||
data: OrderTypes.UpdateOrderReturnReasonWithSelectorDTO[]
|
||||
): Promise<OrderTypes.OrderReturnReasonDTO[]>
|
||||
|
||||
@@ -19,7 +19,7 @@ type InjectedDependencies = {
|
||||
|
||||
export default class OrderService<
|
||||
TEntity extends Order = Order
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
Order
|
||||
)<TEntity> {
|
||||
protected readonly orderRepository_: RepositoryService<TEntity>
|
||||
|
||||
@@ -52,21 +52,21 @@ import PaymentProviderService from "./payment-provider"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
paymentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
captureService: ModulesSdkTypes.InternalModuleService<any>
|
||||
refundService: ModulesSdkTypes.InternalModuleService<any>
|
||||
paymentSessionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
paymentCollectionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
paymentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
captureService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
refundService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
paymentSessionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
paymentCollectionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
paymentProviderService: PaymentProviderService
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
PaymentCollection,
|
||||
Payment,
|
||||
PaymentSession,
|
||||
Capture,
|
||||
Refund,
|
||||
]
|
||||
}
|
||||
|
||||
export default class PaymentModuleService<
|
||||
TPaymentCollection extends PaymentCollection = PaymentCollection,
|
||||
@@ -75,8 +75,7 @@ export default class PaymentModuleService<
|
||||
TRefund extends Refund = Refund,
|
||||
TPaymentSession extends PaymentSession = PaymentSession
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
PaymentCollectionDTO,
|
||||
{
|
||||
PaymentCollection: { dto: PaymentCollectionDTO }
|
||||
@@ -90,11 +89,11 @@ export default class PaymentModuleService<
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
protected paymentService_: ModulesSdkTypes.InternalModuleService<TPayment>
|
||||
protected captureService_: ModulesSdkTypes.InternalModuleService<TCapture>
|
||||
protected refundService_: ModulesSdkTypes.InternalModuleService<TRefund>
|
||||
protected paymentSessionService_: ModulesSdkTypes.InternalModuleService<TPaymentSession>
|
||||
protected paymentCollectionService_: ModulesSdkTypes.InternalModuleService<TPaymentCollection>
|
||||
protected paymentService_: ModulesSdkTypes.IMedusaInternalService<TPayment>
|
||||
protected captureService_: ModulesSdkTypes.IMedusaInternalService<TCapture>
|
||||
protected refundService_: ModulesSdkTypes.IMedusaInternalService<TRefund>
|
||||
protected paymentSessionService_: ModulesSdkTypes.IMedusaInternalService<TPaymentSession>
|
||||
protected paymentCollectionService_: ModulesSdkTypes.IMedusaInternalService<TPaymentCollection>
|
||||
protected paymentProviderService_: PaymentProviderService
|
||||
|
||||
constructor(
|
||||
@@ -126,6 +125,7 @@ export default class PaymentModuleService<
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createPaymentCollections(
|
||||
data: CreatePaymentCollectionDTO,
|
||||
sharedContext?: Context
|
||||
@@ -160,9 +160,10 @@ export default class PaymentModuleService<
|
||||
data: CreatePaymentCollectionDTO[],
|
||||
@MedusaContext() sharedContext?: Context
|
||||
): Promise<PaymentCollection[]> {
|
||||
return this.paymentCollectionService_.create(data, sharedContext)
|
||||
return await this.paymentCollectionService_.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updatePaymentCollections(
|
||||
paymentCollectionId: string,
|
||||
data: PaymentCollectionUpdatableFields,
|
||||
|
||||
@@ -9,7 +9,7 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceListService<
|
||||
TEntity extends PriceList = PriceList
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
PriceList
|
||||
)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
} from "@models"
|
||||
|
||||
import { PriceListService, RuleTypeService } from "@services"
|
||||
import { validatePriceListDates, eventBuilders } from "@utils"
|
||||
import { eventBuilders, validatePriceListDates } from "@utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { PriceListIdPrefix } from "../models/price-list"
|
||||
import { PriceSetIdPrefix } from "../models/price-set"
|
||||
@@ -57,17 +57,17 @@ import { ServiceTypes } from "@types"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
pricingRepository: PricingRepositoryService
|
||||
priceSetService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceSetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
ruleTypeService: RuleTypeService<any>
|
||||
priceRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceSetRuleTypeService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
priceSetRuleTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
priceService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
priceListService: PriceListService<any>
|
||||
priceListRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceListRuleValueService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceListRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
priceListRuleValueService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
PriceList,
|
||||
PriceListRule,
|
||||
PriceListRuleValue,
|
||||
@@ -75,7 +75,7 @@ const generateMethodForModels = [
|
||||
Price,
|
||||
PriceSetRuleType,
|
||||
RuleType,
|
||||
]
|
||||
}
|
||||
|
||||
export default class PricingModuleService<
|
||||
TPriceSet extends PriceSet = PriceSet,
|
||||
@@ -87,8 +87,7 @@ export default class PricingModuleService<
|
||||
TPriceListRule extends PriceListRule = PriceListRule,
|
||||
TPriceListRuleValue extends PriceListRuleValue = PriceListRuleValue
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
PricingTypes.PriceSetDTO,
|
||||
{
|
||||
Price: { dto: PricingTypes.PriceDTO }
|
||||
@@ -111,13 +110,13 @@ export default class PricingModuleService<
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly pricingRepository_: PricingRepositoryService
|
||||
protected readonly ruleTypeService_: RuleTypeService<TRuleType>
|
||||
protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService<TPriceSet>
|
||||
protected readonly priceRuleService_: ModulesSdkTypes.InternalModuleService<TPriceRule>
|
||||
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.InternalModuleService<TPriceSetRuleType>
|
||||
protected readonly priceService_: ModulesSdkTypes.InternalModuleService<TPrice>
|
||||
protected readonly priceSetService_: ModulesSdkTypes.IMedusaInternalService<TPriceSet>
|
||||
protected readonly priceRuleService_: ModulesSdkTypes.IMedusaInternalService<TPriceRule>
|
||||
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.IMedusaInternalService<TPriceSetRuleType>
|
||||
protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService<TPrice>
|
||||
protected readonly priceListService_: PriceListService<TPriceList>
|
||||
protected readonly priceListRuleService_: ModulesSdkTypes.InternalModuleService<TPriceListRule>
|
||||
protected readonly priceListRuleValueService_: ModulesSdkTypes.InternalModuleService<TPriceListRuleValue>
|
||||
protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<TPriceListRule>
|
||||
protected readonly priceListRuleValueService_: ModulesSdkTypes.IMedusaInternalService<TPriceListRuleValue>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -641,6 +640,7 @@ export default class PricingModuleService<
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
@EmitEvents()
|
||||
// @ts-ignore
|
||||
async createPriceLists(
|
||||
data: PricingTypes.CreatePriceListDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -653,6 +653,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
// @ts-ignore
|
||||
async updatePriceLists(
|
||||
data: PricingTypes.UpdatePriceListDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -1334,7 +1335,7 @@ export default class PricingModuleService<
|
||||
sharedContext
|
||||
)
|
||||
|
||||
ruleTypeMap.set(ruleAttribute, ruleType)
|
||||
ruleTypeMap.set(ruleAttribute, ruleType!)
|
||||
}
|
||||
|
||||
const [priceListRule] = await this.priceListRuleService_.create(
|
||||
|
||||
@@ -13,7 +13,7 @@ type InjectedDependencies = {
|
||||
|
||||
export default class RuleTypeService<
|
||||
TEntity extends RuleType = RuleType
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
RuleType
|
||||
)<TEntity> {
|
||||
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
@@ -58,25 +58,25 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
productService: ProductService<any>
|
||||
productVariantService: ModulesSdkTypes.InternalModuleService<any, any>
|
||||
productTagService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productVariantService: ModulesSdkTypes.IMedusaInternalService<any, any>
|
||||
productTagService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productCategoryService: ProductCategoryService<any>
|
||||
productCollectionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productImageService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productTypeService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productOptionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productOptionValueService: ModulesSdkTypes.InternalModuleService<any>
|
||||
productCollectionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productImageService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productOptionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productOptionValueService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
eventBusModuleService?: IEventBusModuleService
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
{ model: ProductCategory, singular: "Category", plural: "Categories" },
|
||||
{ model: ProductCollection, singular: "Collection", plural: "Collections" },
|
||||
{ model: ProductOption, singular: "Option", plural: "Options" },
|
||||
{ model: ProductTag, singular: "Tag", plural: "Tags" },
|
||||
{ model: ProductType, singular: "Type", plural: "Types" },
|
||||
{ model: ProductVariant, singular: "Variant", plural: "Variants" },
|
||||
]
|
||||
const generateMethodForModels = {
|
||||
ProductCategory: { singular: "Category", plural: "Categories" },
|
||||
ProductCollection: { singular: "Collection", plural: "Collections" },
|
||||
ProductOption: { singular: "Option", plural: "Options" },
|
||||
ProductTag: { singular: "Tag", plural: "Tags" },
|
||||
ProductType: { singular: "Type", plural: "Types" },
|
||||
ProductVariant: { singular: "Variant", plural: "Variants" },
|
||||
}
|
||||
|
||||
export default class ProductModuleService<
|
||||
TProduct extends Product = Product,
|
||||
@@ -89,8 +89,7 @@ export default class ProductModuleService<
|
||||
TProductOption extends ProductOption = ProductOption,
|
||||
TProductOptionValue extends ProductOptionValue = ProductOptionValue
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
ProductTypes.ProductDTO,
|
||||
{
|
||||
ProductCategory: {
|
||||
@@ -130,21 +129,21 @@ export default class ProductModuleService<
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly productService_: ProductService<TProduct>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productVariantService_: ModulesSdkTypes.InternalModuleService<TProductVariant>
|
||||
protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService<TProductVariant>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productCategoryService_: ProductCategoryService<TProductCategory>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productTagService_: ModulesSdkTypes.InternalModuleService<TProductTag>
|
||||
protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService<TProductTag>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productCollectionService_: ModulesSdkTypes.InternalModuleService<TProductCollection>
|
||||
protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService<TProductCollection>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productImageService_: ModulesSdkTypes.InternalModuleService<TProductImage>
|
||||
protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService<TProductImage>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productTypeService_: ModulesSdkTypes.InternalModuleService<TProductType>
|
||||
protected readonly productTypeService_: ModulesSdkTypes.IMedusaInternalService<TProductType>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productOptionService_: ModulesSdkTypes.InternalModuleService<TProductOption>
|
||||
protected readonly productOptionService_: ModulesSdkTypes.IMedusaInternalService<TProductOption>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productOptionValueService_: ModulesSdkTypes.InternalModuleService<TProductOptionValue>
|
||||
protected readonly productOptionValueService_: ModulesSdkTypes.IMedusaInternalService<TProductOptionValue>
|
||||
protected readonly eventBusModuleService_?: IEventBusModuleService
|
||||
|
||||
constructor(
|
||||
@@ -185,6 +184,7 @@ export default class ProductModuleService<
|
||||
}
|
||||
|
||||
// TODO: Add options validation, among other things
|
||||
// @ts-ignore
|
||||
createVariants(
|
||||
data: ProductTypes.CreateProductVariantDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -299,6 +299,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? allVariants : allVariants[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateVariants(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductVariantDTO,
|
||||
@@ -413,6 +414,7 @@ export default class ProductModuleService<
|
||||
return productVariants
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createTags(
|
||||
data: ProductTypes.CreateProductTagDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -491,6 +493,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? allTags : allTags[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateTags(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductTagDTO,
|
||||
@@ -544,6 +547,7 @@ export default class ProductModuleService<
|
||||
return isString(idOrSelector) ? updatedTags[0] : updatedTags
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createTypes(
|
||||
data: ProductTypes.CreateProductTypeDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -611,6 +615,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? allTypes : allTypes[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateTypes(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductTypeDTO,
|
||||
@@ -658,6 +663,7 @@ export default class ProductModuleService<
|
||||
return isString(idOrSelector) ? updatedTypes[0] : updatedTypes
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createOptions(
|
||||
data: ProductTypes.CreateProductOptionDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -754,6 +760,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? allOptions : allOptions[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateOptions(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductOptionDTO,
|
||||
@@ -870,6 +877,7 @@ export default class ProductModuleService<
|
||||
return productOptions
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createCollections(
|
||||
data: ProductTypes.CreateProductCollectionDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -989,6 +997,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? allCollections : allCollections[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateCollections(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductCollectionDTO,
|
||||
@@ -1115,6 +1124,7 @@ export default class ProductModuleService<
|
||||
return collections
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createCategories(
|
||||
data: ProductTypes.CreateProductCategoryDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -1218,6 +1228,7 @@ export default class ProductModuleService<
|
||||
return Array.isArray(data) ? result : result[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateCategories(
|
||||
id: string,
|
||||
data: ProductTypes.UpdateProductCategoryDTO,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
FilterableProductProps,
|
||||
FindConfig,
|
||||
ProductTypes,
|
||||
BaseFilterable,
|
||||
FilterableProductProps,
|
||||
} from "@medusajs/types"
|
||||
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Product } from "@models"
|
||||
@@ -21,7 +20,7 @@ type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & {
|
||||
|
||||
export default class ProductService<
|
||||
TEntity extends Product = Product
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
Product
|
||||
)<TEntity> {
|
||||
protected readonly productRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
@@ -10,20 +10,20 @@ import {
|
||||
import {
|
||||
ApplicationMethodAllocation,
|
||||
ApplicationMethodTargetType,
|
||||
arrayDifference,
|
||||
CampaignBudgetType,
|
||||
ComputedActions,
|
||||
deduplicate,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
isPresent,
|
||||
isString,
|
||||
MathBN,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
PromotionType,
|
||||
arrayDifference,
|
||||
deduplicate,
|
||||
isDefined,
|
||||
isPresent,
|
||||
isString,
|
||||
transformPropertiesToBigNumber,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
@@ -47,9 +47,9 @@ import {
|
||||
UpdatePromotionDTO,
|
||||
} from "@types"
|
||||
import {
|
||||
ComputeActionUtils,
|
||||
allowedAllocationForQuantity,
|
||||
areRulesValidForContext,
|
||||
ComputeActionUtils,
|
||||
validateApplicationMethodAttributes,
|
||||
validatePromotionRuleAttributes,
|
||||
} from "@utils"
|
||||
@@ -58,21 +58,21 @@ import { CreatePromotionRuleValueDTO } from "../types/promotion-rule-value"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
promotionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
applicationMethodService: ModulesSdkTypes.InternalModuleService<any>
|
||||
promotionRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
promotionRuleValueService: ModulesSdkTypes.InternalModuleService<any>
|
||||
campaignService: ModulesSdkTypes.InternalModuleService<any>
|
||||
campaignBudgetService: ModulesSdkTypes.InternalModuleService<any>
|
||||
promotionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
applicationMethodService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
promotionRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
promotionRuleValueService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
campaignService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
campaignBudgetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [
|
||||
const generateMethodForModels = {
|
||||
ApplicationMethod,
|
||||
Campaign,
|
||||
CampaignBudget,
|
||||
PromotionRule,
|
||||
PromotionRuleValue,
|
||||
]
|
||||
}
|
||||
|
||||
export default class PromotionModuleService<
|
||||
TApplicationMethod extends ApplicationMethod = ApplicationMethod,
|
||||
@@ -82,8 +82,7 @@ export default class PromotionModuleService<
|
||||
TCampaign extends Campaign = Campaign,
|
||||
TCampaignBudget extends CampaignBudget = CampaignBudget
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
PromotionTypes.PromotionDTO,
|
||||
{
|
||||
ApplicationMethod: { dto: PromotionTypes.ApplicationMethodDTO }
|
||||
@@ -96,12 +95,12 @@ export default class PromotionModuleService<
|
||||
implements PromotionTypes.IPromotionModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected promotionService_: ModulesSdkTypes.InternalModuleService<TPromotion>
|
||||
protected applicationMethodService_: ModulesSdkTypes.InternalModuleService<TApplicationMethod>
|
||||
protected promotionRuleService_: ModulesSdkTypes.InternalModuleService<TPromotionRule>
|
||||
protected promotionRuleValueService_: ModulesSdkTypes.InternalModuleService<TPromotionRuleValue>
|
||||
protected campaignService_: ModulesSdkTypes.InternalModuleService<TCampaign>
|
||||
protected campaignBudgetService_: ModulesSdkTypes.InternalModuleService<TCampaignBudget>
|
||||
protected promotionService_: ModulesSdkTypes.IMedusaInternalService<TPromotion>
|
||||
protected applicationMethodService_: ModulesSdkTypes.IMedusaInternalService<TApplicationMethod>
|
||||
protected promotionRuleService_: ModulesSdkTypes.IMedusaInternalService<TPromotionRule>
|
||||
protected promotionRuleValueService_: ModulesSdkTypes.IMedusaInternalService<TPromotionRuleValue>
|
||||
protected campaignService_: ModulesSdkTypes.IMedusaInternalService<TCampaign>
|
||||
protected campaignBudgetService_: ModulesSdkTypes.IMedusaInternalService<TCampaignBudget>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -839,6 +838,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
// @ts-ignore
|
||||
async updatePromotionRules(
|
||||
data: PromotionTypes.UpdatePromotionRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -848,7 +848,7 @@ export default class PromotionModuleService<
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.listPromotionRules(
|
||||
return await this.listPromotionRules(
|
||||
{ id: updatedPromotionRules.map((r) => r.id) },
|
||||
{ relations: ["values"] },
|
||||
sharedContext
|
||||
@@ -1153,6 +1153,7 @@ export default class PromotionModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async createCampaigns(
|
||||
data: PromotionTypes.CreateCampaignDTO,
|
||||
sharedContext?: Context
|
||||
@@ -1262,6 +1263,7 @@ export default class PromotionModuleService<
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async updateCampaigns(
|
||||
data: PromotionTypes.UpdateCampaignDTO,
|
||||
sharedContext?: Context
|
||||
|
||||
@@ -6,7 +6,7 @@ export default async ({ container }: LoaderOptions): Promise<void> => {
|
||||
// TODO: Add default logger to the container when running tests
|
||||
const logger =
|
||||
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
const countryService_: ModulesSdkTypes.InternalModuleService<Country> =
|
||||
const countryService_: ModulesSdkTypes.IMedusaInternalService<Country> =
|
||||
container.resolve("countryService")
|
||||
|
||||
try {
|
||||
|
||||
@@ -32,18 +32,17 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
regionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
countryService: ModulesSdkTypes.InternalModuleService<any>
|
||||
regionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
countryService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [Country]
|
||||
const generateMethodForModels = { Country }
|
||||
|
||||
export default class RegionModuleService<
|
||||
TRegion extends Region = Region,
|
||||
TCountry extends Country = Country
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
RegionDTO,
|
||||
{
|
||||
Country: {
|
||||
@@ -54,8 +53,8 @@ export default class RegionModuleService<
|
||||
implements IRegionModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly regionService_: ModulesSdkTypes.InternalModuleService<TRegion>
|
||||
protected readonly countryService_: ModulesSdkTypes.InternalModuleService<TCountry>
|
||||
protected readonly regionService_: ModulesSdkTypes.IMedusaInternalService<TRegion>
|
||||
protected readonly countryService_: ModulesSdkTypes.IMedusaInternalService<TCountry>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, regionService, countryService }: InjectedDependencies,
|
||||
|
||||
@@ -27,21 +27,21 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
salesChannelService: ModulesSdkTypes.InternalModuleService<any>
|
||||
salesChannelService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class SalesChannelModuleService<
|
||||
TEntity extends SalesChannel = SalesChannel
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
SalesChannelDTO,
|
||||
{}
|
||||
>(SalesChannel, [], entityNameToLinkableKeysMap)
|
||||
extends ModulesSdkUtils.MedusaService<SalesChannelDTO>(
|
||||
SalesChannel,
|
||||
{},
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
implements ISalesChannelModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly salesChannelService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, salesChannelService }: InjectedDependencies,
|
||||
|
||||
@@ -2,47 +2,45 @@ import { InternalModuleDeclaration } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
Context,
|
||||
CreateStockLocationInput,
|
||||
DAL,
|
||||
FilterableStockLocationProps,
|
||||
IEventBusService,
|
||||
IStockLocationServiceNext,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
StockLocationAddressInput,
|
||||
StockLocationTypes,
|
||||
ModulesSdkTypes,
|
||||
DAL,
|
||||
IStockLocationServiceNext,
|
||||
FilterableStockLocationProps,
|
||||
UpdateStockLocationNextInput,
|
||||
UpsertStockLocationInput,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isString,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
isString,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { StockLocation, StockLocationAddress } from "../models"
|
||||
import { UpdateStockLocationNextInput } from "@medusajs/types"
|
||||
import { UpsertStockLocationInput } from "@medusajs/types"
|
||||
import { promiseAll } from "@medusajs/utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
eventBusModuleService: IEventBusService
|
||||
baseRepository: DAL.RepositoryService
|
||||
stockLocationService: ModulesSdkTypes.InternalModuleService<any>
|
||||
stockLocationAddressService: ModulesSdkTypes.InternalModuleService<any>
|
||||
stockLocationService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
stockLocationAddressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = [StockLocationAddress]
|
||||
const generateMethodForModels = { StockLocationAddress }
|
||||
|
||||
/**
|
||||
* Service for managing stock locations.
|
||||
*/
|
||||
|
||||
export default class StockLocationModuleService<
|
||||
TEntity extends StockLocation = StockLocation,
|
||||
TStockLocationAddress extends StockLocationAddress = StockLocationAddress
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
StockLocationTypes.StockLocationDTO,
|
||||
{
|
||||
StockLocation: { dto: StockLocationTypes.StockLocationDTO }
|
||||
@@ -53,8 +51,8 @@ export default class StockLocationModuleService<
|
||||
{
|
||||
protected readonly eventBusModuleService_: IEventBusService
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly stockLocationService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly stockLocationAddressService_: ModulesSdkTypes.InternalModuleService<TStockLocationAddress>
|
||||
protected readonly stockLocationService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
protected readonly stockLocationAddressService_: ModulesSdkTypes.IMedusaInternalService<TStockLocationAddress>
|
||||
|
||||
constructor(
|
||||
{
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
IStoreModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
IStoreModuleService,
|
||||
StoreTypes,
|
||||
Context,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
isString,
|
||||
promiseAll,
|
||||
removeUndefined,
|
||||
} from "@medusajs/utils"
|
||||
@@ -22,16 +22,15 @@ import { Store } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { UpdateStoreInput } from "@types"
|
||||
|
||||
const generateMethodForModels = []
|
||||
const generateMethodForModels = {}
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
storeService: ModulesSdkTypes.InternalModuleService<any>
|
||||
storeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
export default class StoreModuleService<TEntity extends Store = Store>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
StoreTypes.StoreDTO,
|
||||
{
|
||||
Store: { dto: StoreTypes.StoreDTO }
|
||||
@@ -40,7 +39,7 @@ export default class StoreModuleService<TEntity extends Store = Store>
|
||||
implements IStoreModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly storeService_: ModulesSdkTypes.InternalModuleService<TEntity>
|
||||
protected readonly storeService_: ModulesSdkTypes.IMedusaInternalService<TEntity>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, storeService }: InjectedDependencies,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
ITaxModuleService,
|
||||
ITaxProvider,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
TaxRegionDTO,
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
isDefined,
|
||||
isString,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { TaxProvider, TaxRate, TaxRateRule, TaxRegion } from "@models"
|
||||
@@ -24,14 +24,14 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
taxRateService: ModulesSdkTypes.InternalModuleService<any>
|
||||
taxRegionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
taxRateRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
taxProviderService: ModulesSdkTypes.InternalModuleService<any>
|
||||
taxRateService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
taxRegionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
taxRateRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
taxProviderService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
[key: `tp_${string}`]: ITaxProvider
|
||||
}
|
||||
|
||||
const generateForModels = [TaxRegion, TaxRateRule, TaxProvider]
|
||||
const generateForModels = { TaxRegion, TaxRateRule, TaxProvider }
|
||||
|
||||
type ItemWithRates = {
|
||||
rates: TaxRate[]
|
||||
@@ -44,8 +44,7 @@ export default class TaxModuleService<
|
||||
TTaxRateRule extends TaxRateRule = TaxRateRule,
|
||||
TTaxProvider extends TaxProvider = TaxProvider
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
TaxTypes.TaxRateDTO,
|
||||
{
|
||||
TaxRegion: { dto: TaxTypes.TaxRegionDTO }
|
||||
@@ -57,10 +56,10 @@ export default class TaxModuleService<
|
||||
{
|
||||
protected readonly container_: InjectedDependencies
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected taxRateService_: ModulesSdkTypes.InternalModuleService<TTaxRate>
|
||||
protected taxRegionService_: ModulesSdkTypes.InternalModuleService<TTaxRegion>
|
||||
protected taxRateRuleService_: ModulesSdkTypes.InternalModuleService<TTaxRateRule>
|
||||
protected taxProviderService_: ModulesSdkTypes.InternalModuleService<TTaxProvider>
|
||||
protected taxRateService_: ModulesSdkTypes.IMedusaInternalService<TTaxRate>
|
||||
protected taxRegionService_: ModulesSdkTypes.IMedusaInternalService<TTaxRegion>
|
||||
protected taxRateRuleService_: ModulesSdkTypes.IMedusaInternalService<TTaxRateRule>
|
||||
protected taxProviderService_: ModulesSdkTypes.IMedusaInternalService<TTaxProvider>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -293,6 +292,7 @@ export default class TaxModuleService<
|
||||
return Array.isArray(data) ? serialized : serialized[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createTaxRegions(
|
||||
data: TaxTypes.CreateTaxRegionDTO,
|
||||
sharedContext?: Context
|
||||
@@ -349,6 +349,7 @@ export default class TaxModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createTaxRateRules(
|
||||
data: TaxTypes.CreateTaxRateRuleDTO,
|
||||
sharedContext?: Context
|
||||
|
||||
@@ -2,10 +2,10 @@ import * as crypto from "crypto"
|
||||
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
InjectTransactionManager,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
arrayDifference,
|
||||
} from "@medusajs/utils"
|
||||
import jwt, { JwtPayload } from "jsonwebtoken"
|
||||
|
||||
@@ -21,7 +21,7 @@ const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000
|
||||
|
||||
export default class InviteService<
|
||||
TEntity extends Invite = Invite
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
Invite
|
||||
)<TEntity> {
|
||||
// eslint-disable-next-line max-len
|
||||
|
||||
@@ -23,19 +23,18 @@ import InviteService from "./invite"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
userService: ModulesSdkTypes.InternalModuleService<any>
|
||||
userService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
inviteService: InviteService<any>
|
||||
eventBusModuleService: IEventBusModuleService
|
||||
}
|
||||
|
||||
const generateMethodForModels = [Invite]
|
||||
const generateMethodForModels = { Invite }
|
||||
|
||||
export default class UserModuleService<
|
||||
TUser extends User = User,
|
||||
TInvite extends Invite = Invite
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
UserTypes.UserDTO,
|
||||
{
|
||||
Invite: {
|
||||
@@ -51,7 +50,7 @@ export default class UserModuleService<
|
||||
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
protected readonly userService_: ModulesSdkTypes.InternalModuleService<TUser>
|
||||
protected readonly userService_: ModulesSdkTypes.IMedusaInternalService<TUser>
|
||||
protected readonly inviteService_: InviteService<TInvite>
|
||||
|
||||
constructor(
|
||||
@@ -199,6 +198,7 @@ export default class UserModuleService<
|
||||
return Array.isArray(data) ? serializedUsers : serializedUsers[0]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
createInvites(
|
||||
data: UserTypes.CreateInviteDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -265,6 +265,7 @@ export default class UserModuleService<
|
||||
return await this.inviteService_.create(toCreate, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
updateInvites(
|
||||
data: UserTypes.UpdateInviteDTO[],
|
||||
sharedContext?: Context
|
||||
|
||||
@@ -24,13 +24,13 @@ import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
workflowExecutionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
workflowOrchestratorService: WorkflowOrchestratorService
|
||||
}
|
||||
|
||||
export class WorkflowsModuleService implements IWorkflowEngineService {
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
protected workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -16,7 +16,7 @@ import { CronExpression, parseExpression } from "cron-parser"
|
||||
export class InMemoryDistributedTransactionStorage
|
||||
implements IDistributedTransactionStorage, IDistributedSchedulerStorage
|
||||
{
|
||||
private workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
private workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
private workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
private storage: Map<string, TransactionCheckpoint> = new Map()
|
||||
@@ -35,7 +35,7 @@ export class InMemoryDistributedTransactionStorage
|
||||
constructor({
|
||||
workflowExecutionService,
|
||||
}: {
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
workflowExecutionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}) {
|
||||
this.workflowExecutionService_ = workflowExecutionService
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
workflowExecutionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
workflowOrchestratorService: WorkflowOrchestratorService
|
||||
redisDisconnectHandler: () => Promise<void>
|
||||
}
|
||||
|
||||
export class WorkflowsModuleService implements IWorkflowEngineService {
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
protected workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
protected redisDisconnectHandler_: () => Promise<void>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export class RedisDistributedTransactionStorage
|
||||
implements IDistributedTransactionStorage, IDistributedSchedulerStorage
|
||||
{
|
||||
private static TTL_AFTER_COMPLETED = 60 * 15 // 15 minutes
|
||||
private workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
private workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
private workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
private redisClient: Redis
|
||||
@@ -37,7 +37,7 @@ export class RedisDistributedTransactionStorage
|
||||
redisWorkerConnection,
|
||||
redisQueueName,
|
||||
}: {
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
workflowExecutionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
redisConnection: Redis
|
||||
redisWorkerConnection: Redis
|
||||
redisQueueName: string
|
||||
|
||||
Reference in New Issue
Block a user