feat: refactor module joiner config and links generation (#7859)
* feat: refactor module joiner config and links generation * improve typings * WIP * WIP * WIP * rename type file * create link config * finish typings and add utils * improve links * WIP typings * finalize ExportModule utils * finalize ExportModule utils * fix: dml tests * improve and fixes * simplify typings with id changes * add toJSON * multiple fixes and entity builder fixes * fix currency searchable * fix tests * medusa service refactoring * cleanup * cleanup and fixes * make module name optional * renaming --------- Co-authored-by: Harminder Virk <virk.officials@gmail.com>
This commit is contained in:
1 parent
5aa62e59e4
commit
617a5972bf
89 files changed
+1706
-950
No files matched your search
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.API_KEY)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { ApiKey } from "@models"
|
||||
import {
|
||||
CreateApiKeyDTO,
|
||||
@@ -41,7 +41,7 @@ type InjectedDependencies = {
|
||||
export default class ApiKeyModuleService
|
||||
extends MedusaService<{
|
||||
ApiKey: { dto: ApiKeyTypes.ApiKeyDTO }
|
||||
}>({ ApiKey }, entityNameToLinkableKeysMap)
|
||||
}>({ ApiKey })
|
||||
implements IApiKeyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import { AuthIdentity } from "@models"
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.AUTH, {
|
||||
entityQueryingConfig: [AuthIdentity],
|
||||
models: [AuthIdentity],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
import { AuthIdentity, ProviderIdentity } from "@models"
|
||||
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
import {
|
||||
InjectManager,
|
||||
@@ -32,7 +32,7 @@ export default class AuthModuleService
|
||||
extends MedusaService<{
|
||||
AuthIdentity: { dto: AuthTypes.AuthIdentityDTO }
|
||||
ProviderIdentity: { dto: AuthTypes.ProviderIdentityDTO }
|
||||
}>({ AuthIdentity, ProviderIdentity }, entityNameToLinkableKeysMap)
|
||||
}>({ AuthIdentity, ProviderIdentity })
|
||||
implements AuthTypes.IAuthModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CART)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
UpdateLineItemDTO,
|
||||
UpdateShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -74,7 +74,7 @@ export default class CartModuleService
|
||||
ShippingMethod: { dto: CartTypes.CartShippingMethodDTO }
|
||||
ShippingMethodAdjustment: { dto: CartTypes.ShippingMethodAdjustmentDTO }
|
||||
ShippingMethodTaxLine: { dto: CartTypes.ShippingMethodTaxLineDTO }
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateMethodForModels)
|
||||
implements ICartModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { CurrencyModuleService } from "@services"
|
||||
import initialDataLoader from "./loaders/initial-data"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = CurrencyModuleService
|
||||
const loaders = [initialDataLoader]
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
export default Module({
|
||||
name: Modules.CURRENCY,
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
})
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
|
||||
primaryKeys: ["code"],
|
||||
@@ -11,6 +6,3 @@ export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
|
||||
currency_code: "currency",
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -1,7 +1,7 @@
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
export default model.define("currency", {
|
||||
code: model.text().primaryKey().searchable(),
|
||||
code: model.text().searchable().primaryKey(),
|
||||
symbol: model.text(),
|
||||
symbol_native: model.text(),
|
||||
name: model.text().searchable(),
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -22,8 +22,8 @@ type InjectedDependencies = {
|
||||
|
||||
export default class CurrencyModuleService
|
||||
extends MedusaService<{
|
||||
Currency: { dto: CurrencyTypes.CurrencyDTO }
|
||||
}>({ Currency }, entityNameToLinkableKeysMap)
|
||||
Currency: { dto: CurrencyTypes.CurrencyDTO; model: typeof Currency }
|
||||
}>({ Currency })
|
||||
implements ICurrencyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CUSTOMER, {
|
||||
alias: [
|
||||
@@ -16,6 +11,3 @@ export const joinerConfig = defineJoinerConfig(Modules.CUSTOMER, {
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
CustomerGroup,
|
||||
CustomerGroupCustomer,
|
||||
} from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -42,10 +42,7 @@ export default class CustomerModuleService
|
||||
Customer: { dto: CustomerDTO }
|
||||
CustomerGroup: { dto: CustomerGroupDTO }
|
||||
CustomerGroupCustomer: { dto: CustomerGroupCustomerDTO }
|
||||
}>(
|
||||
{ Address, Customer, CustomerGroup, CustomerGroupCustomer },
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
}>({ Address, Customer, CustomerGroup, CustomerGroupCustomer })
|
||||
implements ICustomerModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.FILE, {
|
||||
entityQueryingConfig: [{ name: "File" }],
|
||||
models: [{ name: "File" }],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap({})
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
Fulfillment,
|
||||
FulfillmentSet,
|
||||
@@ -19,6 +14,3 @@ export const joinerConfig = defineJoinerConfig(Modules.FULFILLMENT, {
|
||||
shipping_option_rule_id: ShippingOptionRule.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -47,7 +47,7 @@ import {
|
||||
isContextValid,
|
||||
validateAndNormalizeRules,
|
||||
} from "@utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { UpdateShippingOptionsInput } from "../types/service"
|
||||
import { buildCreatedShippingOptionEvents } from "../utils/events"
|
||||
import FulfillmentProviderService from "./fulfillment-provider"
|
||||
@@ -87,7 +87,7 @@ export default class FulfillmentModuleService
|
||||
ShippingOptionRule: { dto: FulfillmentTypes.ShippingOptionRuleDTO }
|
||||
ShippingOptionType: { dto: FulfillmentTypes.ShippingOptionTypeDTO }
|
||||
FulfillmentProvider: { dto: FulfillmentTypes.FulfillmentProviderDTO }
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateMethodForModels)
|
||||
implements IFulfillmentModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.INVENTORY, {
|
||||
alias: [
|
||||
@@ -35,6 +30,3 @@ export const joinerConfig = defineJoinerConfig(Modules.INVENTORY, {
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -8,9 +8,10 @@ type InjectedDependencies = {
|
||||
inventoryLevelRepository: InventoryLevelRepository
|
||||
}
|
||||
|
||||
export default class InventoryLevelService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
export default class InventoryLevelService extends ModulesSdkUtils.MedusaInternalService<
|
||||
InjectedDependencies,
|
||||
InventoryLevel
|
||||
)<InventoryLevel> {
|
||||
>(InventoryLevel) {
|
||||
protected readonly inventoryLevelRepository: InventoryLevelRepository
|
||||
|
||||
constructor(container: InjectedDependencies) {
|
||||
|
||||
@@ -11,22 +11,22 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import { IInventoryService } from "@medusajs/types/dist/inventory"
|
||||
import {
|
||||
arrayDifference,
|
||||
CommonEvents,
|
||||
EmitEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
InventoryEvents,
|
||||
isDefined,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaService,
|
||||
arrayDifference,
|
||||
isDefined,
|
||||
isString,
|
||||
partitionArray,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { InventoryItem, InventoryLevel, ReservationItem } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import InventoryLevelService from "./inventory-level"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -47,14 +47,11 @@ export default class InventoryModuleService
|
||||
ReservationItem: {
|
||||
dto: InventoryTypes.ReservationItemDTO
|
||||
}
|
||||
}>(
|
||||
{
|
||||
InventoryItem,
|
||||
InventoryLevel,
|
||||
ReservationItem,
|
||||
},
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
}>({
|
||||
InventoryItem,
|
||||
InventoryLevel,
|
||||
ReservationItem,
|
||||
})
|
||||
implements IInventoryService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.NOTIFICATION, {
|
||||
entityQueryingConfig: [{ name: "Notification" }],
|
||||
models: [{ name: "Notification" }],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
InferEntityType,
|
||||
INotificationModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
NotificationTypes,
|
||||
InferEntityType,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { Notification } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import NotificationProviderService from "./notification-provider"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -31,7 +31,7 @@ type InjectedDependencies = {
|
||||
export default class NotificationModuleService
|
||||
extends MedusaService<{
|
||||
Notification: { dto: NotificationTypes.NotificationDTO }
|
||||
}>({ Notification }, entityNameToLinkableKeysMap)
|
||||
}>({ Notification })
|
||||
implements INotificationModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -12,9 +12,10 @@ type InjectedDependencies = {
|
||||
]: NotificationTypes.INotificationProvider
|
||||
}
|
||||
|
||||
export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
NotificationProvider
|
||||
) {
|
||||
export default class NotificationProviderService extends ModulesSdkUtils.MedusaInternalService<
|
||||
InjectedDependencies,
|
||||
typeof NotificationProvider
|
||||
>(NotificationProvider) {
|
||||
protected readonly notificationProviderRepository_: DAL.RepositoryService<
|
||||
InferEntityType<typeof NotificationProvider>
|
||||
>
|
||||
@@ -50,6 +51,8 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
|
||||
): Promise<InferEntityType<typeof NotificationProvider> | undefined> {
|
||||
if (!this.providersCache) {
|
||||
const providers = await this.notificationProviderRepository_.find()
|
||||
|
||||
type name = (typeof NotificationProvider)["name"]
|
||||
this.providersCache = new Map(
|
||||
providers.flatMap((provider) =>
|
||||
provider.channels.map((c) => [c, provider])
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
// TODO: review configuration
|
||||
export const joinerConfig = defineJoinerConfig(Modules.ORDER)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -20,9 +20,10 @@ type InjectedDependencies = {
|
||||
orderChangeRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class OrderChangeService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
export default class OrderChangeService extends ModulesSdkUtils.MedusaInternalService<
|
||||
InjectedDependencies,
|
||||
OrderChange
|
||||
)<OrderChange> {
|
||||
>(OrderChange) {
|
||||
protected readonly orderChangeRepository_: RepositoryService<OrderChange>
|
||||
|
||||
constructor(container: InjectedDependencies) {
|
||||
|
||||
@@ -65,7 +65,7 @@ import {
|
||||
UpdateOrderLineItemTaxLineDTO,
|
||||
UpdateOrderShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import {
|
||||
applyChangesToOrder,
|
||||
ApplyOrderChangeDTO,
|
||||
@@ -165,7 +165,7 @@ export default class OrderModuleService<
|
||||
ReturnItem: { dto: any } // TODO: Add return item dto
|
||||
OrderClaim: { dto: any } // TODO: Add claim dto
|
||||
OrderExchange: { dto: any } // TODO: Add exchange dto
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateMethodForModels)
|
||||
implements IOrderModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -17,9 +17,10 @@ type InjectedDependencies = {
|
||||
orderRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class OrderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
export default class OrderService extends ModulesSdkUtils.MedusaInternalService<
|
||||
InjectedDependencies,
|
||||
Order
|
||||
)<Order> {
|
||||
>(Order) {
|
||||
protected readonly orderRepository_: RepositoryService<Order>
|
||||
|
||||
constructor(container: InjectedDependencies) {
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
Payment,
|
||||
PaymentCollection,
|
||||
@@ -12,18 +7,10 @@ import {
|
||||
} from "@models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PAYMENT, {
|
||||
entityQueryingConfig: [
|
||||
Payment,
|
||||
PaymentCollection,
|
||||
PaymentProvider,
|
||||
PaymentSession,
|
||||
],
|
||||
models: [Payment, PaymentCollection, PaymentProvider, PaymentSession],
|
||||
linkableKeys: {
|
||||
payment_id: Payment.name,
|
||||
payment_collection_id: PaymentCollection.name,
|
||||
payment_provider_id: PaymentProvider.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
PaymentSession,
|
||||
Refund,
|
||||
} from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import PaymentProviderService from "./payment-provider"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -76,7 +76,7 @@ export default class PaymentModuleService
|
||||
Payment: { dto: PaymentDTO }
|
||||
Capture: { dto: CaptureDTO }
|
||||
Refund: { dto: RefundDTO }
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateMethodForModels)
|
||||
implements IPaymentModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import { Price, PriceList, PriceSet } from "@models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PRICING, {
|
||||
entityQueryingConfig: [PriceSet, PriceList, Price],
|
||||
models: [PriceSet, PriceList, Price],
|
||||
linkableKeys: {
|
||||
price_set_id: PriceSet.name,
|
||||
price_list_id: PriceList.name,
|
||||
price_id: Price.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -38,7 +38,7 @@ import { Price, PriceList, PriceListRule, PriceRule, PriceSet } from "@models"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
import { eventBuilders, validatePriceListDates } from "@utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { CreatePriceListDTO, UpsertPriceDTO } from "src/types/services"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -70,7 +70,7 @@ export default class PricingModuleService
|
||||
}
|
||||
PriceList: { dto: PricingTypes.PriceListDTO }
|
||||
PriceListRule: { dto: PricingTypes.PriceListRuleDTO }
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateMethodForModels)
|
||||
implements PricingTypes.IPricingModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, {
|
||||
primaryKeys: ["id", "handle"],
|
||||
// This module provides more alias than the default config builder
|
||||
alias: [
|
||||
{
|
||||
@@ -58,6 +54,3 @@ export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, {
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -51,7 +51,7 @@ import {
|
||||
UpdateTypeInput,
|
||||
} from "../types"
|
||||
import { eventBuilders } from "../utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
|
||||
import { joinerConfig } from "./../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -90,18 +90,15 @@ export default class ProductModuleService
|
||||
ProductVariant: {
|
||||
dto: ProductTypes.ProductVariantDTO
|
||||
}
|
||||
}>(
|
||||
{
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductCollection,
|
||||
ProductOption,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
ProductVariant,
|
||||
},
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
}>({
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductCollection,
|
||||
ProductOption,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
ProductVariant,
|
||||
})
|
||||
implements ProductTypes.IProductModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -18,9 +18,10 @@ type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & {
|
||||
}
|
||||
}
|
||||
|
||||
export default class ProductService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
export default class ProductService extends ModulesSdkUtils.MedusaInternalService<
|
||||
InjectedDependencies,
|
||||
Product
|
||||
)<Product> {
|
||||
>(Product) {
|
||||
protected readonly productRepository_: DAL.RepositoryService<Product>
|
||||
|
||||
constructor({ productRepository }: InjectedDependencies) {
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import { Campaign, Promotion, PromotionRule } from "@models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.PROMOTION, {
|
||||
entityQueryingConfig: [Promotion, Campaign, PromotionRule],
|
||||
models: [Promotion, Campaign, PromotionRule],
|
||||
linkableKeys: {
|
||||
promotion_id: Promotion.name,
|
||||
campaign_id: Campaign.name,
|
||||
promotion_rule_id: PromotionRule.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaService,
|
||||
ModulesSdkUtils,
|
||||
PromotionType,
|
||||
transformPropertiesToBigNumber,
|
||||
} from "@medusajs/utils"
|
||||
@@ -54,7 +53,7 @@ import {
|
||||
validateApplicationMethodAttributes,
|
||||
validatePromotionRuleAttributes,
|
||||
} from "@utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { CreatePromotionRuleValueDTO } from "../types/promotion-rule-value"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -75,17 +74,14 @@ export default class PromotionModuleService
|
||||
CampaignBudget: { dto: PromotionTypes.CampaignBudgetDTO }
|
||||
PromotionRule: { dto: PromotionTypes.PromotionRuleDTO }
|
||||
PromotionRuleValue: { dto: PromotionTypes.PromotionRuleValueDTO }
|
||||
}>(
|
||||
{
|
||||
Promotion,
|
||||
ApplicationMethod,
|
||||
Campaign,
|
||||
CampaignBudget,
|
||||
PromotionRule,
|
||||
PromotionRuleValue,
|
||||
},
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
}>({
|
||||
Promotion,
|
||||
ApplicationMethod,
|
||||
Campaign,
|
||||
CampaignBudget,
|
||||
PromotionRule,
|
||||
PromotionRuleValue,
|
||||
})
|
||||
implements PromotionTypes.IPromotionModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.REGION)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
CreateRegionDTO,
|
||||
DAL,
|
||||
FilterableRegionProps,
|
||||
IRegionModuleService,
|
||||
InferEntityType,
|
||||
InternalModuleDeclaration,
|
||||
IRegionModuleService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
RegionCountryDTO,
|
||||
@@ -15,20 +15,20 @@ import {
|
||||
UpsertRegionDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
getDuplicates,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaService,
|
||||
arrayDifference,
|
||||
getDuplicates,
|
||||
isString,
|
||||
promiseAll,
|
||||
removeUndefined,
|
||||
} from "@medusajs/utils"
|
||||
import { RegionCountry as Country, Region } from "@models"
|
||||
import { Region, RegionCountry as Country } from "@models"
|
||||
import { UpdateRegionInput } from "@types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -44,7 +44,7 @@ export default class RegionModuleService
|
||||
Country: {
|
||||
dto: RegionCountryDTO
|
||||
}
|
||||
}>({ Region, Country }, entityNameToLinkableKeysMap)
|
||||
}>({ Region, Country })
|
||||
implements IRegionModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.SALES_CHANNEL)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
ModulesSdkTypes,
|
||||
SalesChannelDTO,
|
||||
UpdateSalesChannelDTO,
|
||||
UpsertSalesChannelDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
@@ -20,10 +21,8 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { SalesChannel } from "@models"
|
||||
|
||||
import { UpsertSalesChannelDTO } from "@medusajs/types"
|
||||
import { UpdateSalesChanneInput } from "@types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -31,10 +30,9 @@ type InjectedDependencies = {
|
||||
}
|
||||
|
||||
export default class SalesChannelModuleService
|
||||
extends MedusaService<{ SalesChannel: { dto: SalesChannelDTO } }>(
|
||||
{ SalesChannel },
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
extends MedusaService<{ SalesChannel: { dto: SalesChannelDTO } }>({
|
||||
SalesChannel,
|
||||
})
|
||||
implements ISalesChannelModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
import { StockLocation } from "./models"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.STOCK_LOCATION, {
|
||||
@@ -12,6 +7,3 @@ export const joinerConfig = defineJoinerConfig(Modules.STOCK_LOCATION, {
|
||||
location_id: StockLocation.name,
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
MedusaService,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { StockLocation, StockLocationAddress } from "../models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -38,7 +38,7 @@ export default class StockLocationModuleService
|
||||
extends MedusaService<{
|
||||
StockLocation: { dto: StockLocationTypes.StockLocationDTO }
|
||||
StockLocationAddress: { dto: StockLocationTypes.StockLocationAddressDTO }
|
||||
}>({ StockLocation, StockLocationAddress }, entityNameToLinkableKeysMap)
|
||||
}>({ StockLocation, StockLocationAddress })
|
||||
implements IStockLocationService
|
||||
{
|
||||
protected readonly eventBusModuleService_: IEventBusService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.STORE)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { Store, StoreCurrency } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { UpdateStoreInput } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -32,7 +32,7 @@ export default class StoreModuleService
|
||||
extends MedusaService<{
|
||||
Store: { dto: StoreTypes.StoreDTO }
|
||||
StoreCurrency: { dto: StoreTypes.StoreCurrencyDTO }
|
||||
}>({ Store, StoreCurrency }, entityNameToLinkableKeysMap)
|
||||
}>({ Store, StoreCurrency })
|
||||
implements IStoreModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.TAX)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { TaxProvider, TaxRate, TaxRateRule, TaxRegion } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -44,7 +44,7 @@ export default class TaxModuleService
|
||||
TaxRegion: { dto: TaxTypes.TaxRegionDTO }
|
||||
TaxRateRule: { dto: TaxTypes.TaxRateRuleDTO }
|
||||
TaxProvider: { dto: TaxTypes.TaxProviderDTO }
|
||||
}>(generateForModels, entityNameToLinkableKeysMap)
|
||||
}>(generateForModels)
|
||||
implements ITaxModuleService
|
||||
{
|
||||
protected readonly container_: InjectedDependencies
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.USER)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
UserEvents,
|
||||
} from "@medusajs/utils"
|
||||
import jwt, { JwtPayload } from "jsonwebtoken"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import crypto from "node:crypto"
|
||||
|
||||
import { Invite, User } from "@models"
|
||||
@@ -41,7 +41,7 @@ export default class UserModuleService
|
||||
Invite: {
|
||||
dto: UserTypes.InviteDTO
|
||||
}
|
||||
}>({ User, Invite }, entityNameToLinkableKeysMap)
|
||||
}>({ User, Invite })
|
||||
implements UserTypes.IUserModuleService
|
||||
{
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.WORKFLOW_ENGINE)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { WorkflowExecution } from "@models"
|
||||
import { WorkflowOrchestratorService } from "@services"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -29,7 +29,7 @@ export class WorkflowsModuleService<
|
||||
TWorkflowExecution extends WorkflowExecution = WorkflowExecution
|
||||
> extends ModulesSdkUtils.MedusaService<{
|
||||
WorkflowExecution: { dto: WorkflowExecution }
|
||||
}>({ WorkflowExecution }, entityNameToLinkableKeysMap) {
|
||||
}>({ WorkflowExecution }) {
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<TWorkflowExecution>
|
||||
protected workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.WORKFLOW_ENGINE)
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { WorkflowExecution } from "@models"
|
||||
import { WorkflowOrchestratorService } from "@services"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -30,7 +30,7 @@ export class WorkflowsModuleService<
|
||||
TWorkflowExecution extends WorkflowExecution = WorkflowExecution
|
||||
> extends ModulesSdkUtils.MedusaService<{
|
||||
WorkflowExecution: { dto: WorkflowExecution }
|
||||
}>({ WorkflowExecution }, entityNameToLinkableKeysMap) {
|
||||
}>({ WorkflowExecution }) {
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<TWorkflowExecution>
|
||||
protected workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
Reference in new issue
Block a user