chore: Migrate modules to use the Module util (#7964)

**What**
Apply the `Module` util to each module to handle the export and provide the linkable configuration object.

- Most joiner config that does not have any special config are removed/cleaned up in favor of the autogenerated one or simpler one
- linkable are now available in all modules
- cleaned up the dependencies of the modules

FIXES CORE-2410
This commit is contained in:
Adrien de Peretti
2024-07-05 13:00:40 +00:00
committed by GitHub
parent eafa3560ae
commit b368251ca3
99 changed files with 1267 additions and 488 deletions
@@ -0,0 +1,243 @@
import { moduleIntegrationTestRunner } from "medusa-test-utils"
import { IOrderModuleService } from "@medusajs/types"
import { Module, Modules } from "@medusajs/utils"
import { OrderModuleService } from "@services"
moduleIntegrationTestRunner<IOrderModuleService>({
moduleName: Modules.ORDER,
testSuite: () => {
describe("Order Module Service", () => {
it(`should export the appropriate linkable configuration`, () => {
const linkable = Module(Modules.ORDER, {
service: OrderModuleService,
}).linkable
expect(Object.keys(linkable)).toEqual([
"address",
"adjustmentLine",
"claimItemImage",
"orderClaimItem",
"orderClaim",
"orderExchangeItem",
"orderExchange",
"lineItemAdjustment",
"lineItemTaxLine",
"lineItem",
"orderChangeAction",
"orderChange",
"orderItem",
"orderShippingMethod",
"orderSummary",
"order",
"returnItem",
"returnReason",
"return",
"shippingMethodAdjustment",
"shippingMethodTaxLine",
"shippingMethod",
"taxLine",
"transaction",
])
Object.keys(linkable).forEach((key) => {
delete linkable[key].toJSON
})
expect(linkable).toEqual({
address: {
id: {
linkable: "address_id",
primaryKey: "id",
serviceName: "order",
field: "address",
},
},
adjustmentLine: {
id: {
linkable: "adjustment_line_id",
primaryKey: "id",
serviceName: "order",
field: "adjustmentLine",
},
},
claimItemImage: {
id: {
linkable: "claim_item_image_id",
primaryKey: "id",
serviceName: "order",
field: "claimItemImage",
},
},
orderClaimItem: {
id: {
linkable: "order_claim_item_id",
primaryKey: "id",
serviceName: "order",
field: "orderClaimItem",
},
},
orderClaim: {
id: {
linkable: "order_claim_id",
primaryKey: "id",
serviceName: "order",
field: "orderClaim",
},
},
orderExchangeItem: {
id: {
linkable: "order_exchange_item_id",
primaryKey: "id",
serviceName: "order",
field: "orderExchangeItem",
},
},
orderExchange: {
id: {
linkable: "order_exchange_id",
primaryKey: "id",
serviceName: "order",
field: "orderExchange",
},
},
lineItemAdjustment: {
id: {
linkable: "line_item_adjustment_id",
primaryKey: "id",
serviceName: "order",
field: "lineItemAdjustment",
},
},
lineItemTaxLine: {
id: {
linkable: "line_item_tax_line_id",
primaryKey: "id",
serviceName: "order",
field: "lineItemTaxLine",
},
},
lineItem: {
id: {
linkable: "line_item_id",
primaryKey: "id",
serviceName: "order",
field: "lineItem",
},
},
orderChangeAction: {
id: {
linkable: "order_change_action_id",
primaryKey: "id",
serviceName: "order",
field: "orderChangeAction",
},
},
orderChange: {
id: {
linkable: "order_change_id",
primaryKey: "id",
serviceName: "order",
field: "orderChange",
},
},
orderItem: {
id: {
linkable: "order_item_id",
primaryKey: "id",
serviceName: "order",
field: "orderItem",
},
},
orderShippingMethod: {
id: {
linkable: "order_shipping_method_id",
primaryKey: "id",
serviceName: "order",
field: "orderShippingMethod",
},
},
orderSummary: {
id: {
linkable: "order_summary_id",
primaryKey: "id",
serviceName: "order",
field: "orderSummary",
},
},
order: {
id: {
linkable: "order_id",
primaryKey: "id",
serviceName: "order",
field: "order",
},
},
returnItem: {
id: {
linkable: "return_item_id",
primaryKey: "id",
serviceName: "order",
field: "returnItem",
},
},
returnReason: {
id: {
linkable: "return_reason_id",
primaryKey: "id",
serviceName: "order",
field: "returnReason",
},
},
return: {
id: {
linkable: "return_id",
primaryKey: "id",
serviceName: "order",
field: "return",
},
},
shippingMethodAdjustment: {
id: {
linkable: "shipping_method_adjustment_id",
primaryKey: "id",
serviceName: "order",
field: "shippingMethodAdjustment",
},
},
shippingMethodTaxLine: {
id: {
linkable: "shipping_method_tax_line_id",
primaryKey: "id",
serviceName: "order",
field: "shippingMethodTaxLine",
},
},
shippingMethod: {
id: {
linkable: "shipping_method_id",
primaryKey: "id",
serviceName: "order",
field: "shippingMethod",
},
},
taxLine: {
id: {
linkable: "tax_line_id",
primaryKey: "id",
serviceName: "order",
field: "taxLine",
},
},
transaction: {
id: {
linkable: "transaction_id",
primaryKey: "id",
serviceName: "order",
field: "transaction",
},
},
})
})
})
},
})
+1 -3
View File
@@ -50,8 +50,6 @@
"@mikro-orm/core": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.0",
"dotenv": "^16.4.5",
"knex": "2.4.2"
"awilix": "^8.0.0"
}
}
+4 -12
View File
@@ -1,14 +1,6 @@
import { ModuleExports } from "@medusajs/types"
import { OrderModuleService } from "@services"
import { Module, Modules } from "@medusajs/utils"
const service = OrderModuleService
export const moduleDefinition: ModuleExports = {
service,
}
export * from "./models"
export * from "./services"
export * from "./types"
export default moduleDefinition
export default Module(Modules.ORDER, {
service: OrderModuleService,
})
@@ -1,4 +0,0 @@
import { defineJoinerConfig, Modules } from "@medusajs/utils"
// TODO: review configuration
export const joinerConfig = defineJoinerConfig(Modules.ORDER)
@@ -5,7 +5,6 @@ import {
FindConfig,
InternalModuleDeclaration,
IOrderModuleService,
ModuleJoinerConfig,
ModulesSdkTypes,
OrderDTO,
OrderTypes,
@@ -65,7 +64,6 @@ import {
UpdateOrderLineItemTaxLineDTO,
UpdateOrderShippingMethodTaxLineDTO,
} from "@types"
import { joinerConfig } from "../joiner-config"
import {
applyChangesToOrder,
ApplyOrderChangeDTO,
@@ -239,10 +237,6 @@ export default class OrderModuleService<
this.orderExchangeService_ = orderExchangeService
}
__joinerConfig(): ModuleJoinerConfig {
return joinerConfig
}
private shouldIncludeTotals(config: FindConfig<any>): boolean {
const totalFields = [
"total",