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:
1 parent
eafa3560ae
commit
b368251ca3
99 files changed
+1267
-488
No files matched your search
+108
-1
@@ -1,7 +1,8 @@
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { BigNumber, Modules } from "@medusajs/utils"
|
||||
import { BigNumber, Module, Modules } from "@medusajs/utils"
|
||||
import { CheckConstraintViolationException } from "@mikro-orm/core"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { CartModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -9,6 +10,112 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
moduleName: Modules.CART,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Cart Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.CART, {
|
||||
service: CartModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"address",
|
||||
"adjustmentLine",
|
||||
"cart",
|
||||
"lineItemAdjustment",
|
||||
"lineItemTaxLine",
|
||||
"lineItem",
|
||||
"shippingMethodAdjustment",
|
||||
"shippingMethodTaxLine",
|
||||
"shippingMethod",
|
||||
"taxLine",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
address: {
|
||||
id: {
|
||||
linkable: "address_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "address",
|
||||
},
|
||||
},
|
||||
adjustmentLine: {
|
||||
id: {
|
||||
linkable: "adjustment_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "adjustmentLine",
|
||||
},
|
||||
},
|
||||
cart: {
|
||||
id: {
|
||||
linkable: "cart_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "cart",
|
||||
},
|
||||
},
|
||||
lineItemAdjustment: {
|
||||
id: {
|
||||
linkable: "line_item_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItemAdjustment",
|
||||
},
|
||||
},
|
||||
lineItemTaxLine: {
|
||||
id: {
|
||||
linkable: "line_item_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItemTaxLine",
|
||||
},
|
||||
},
|
||||
lineItem: {
|
||||
id: {
|
||||
linkable: "line_item_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "lineItem",
|
||||
},
|
||||
},
|
||||
shippingMethodAdjustment: {
|
||||
id: {
|
||||
linkable: "shipping_method_adjustment_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethodAdjustment",
|
||||
},
|
||||
},
|
||||
shippingMethodTaxLine: {
|
||||
id: {
|
||||
linkable: "shipping_method_tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethodTaxLine",
|
||||
},
|
||||
},
|
||||
shippingMethod: {
|
||||
id: {
|
||||
linkable: "shipping_method_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "shippingMethod",
|
||||
},
|
||||
},
|
||||
taxLine: {
|
||||
id: {
|
||||
linkable: "tax_line_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "cart",
|
||||
field: "taxLine",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await service
|
||||
|
||||
@@ -45,13 +45,10 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CartModuleService } from "./services"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = CartModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.CART, {
|
||||
service: CartModuleService,
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CART)
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
FindConfig,
|
||||
ICartModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
@@ -39,7 +38,6 @@ import {
|
||||
UpdateLineItemDTO,
|
||||
UpdateShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -115,10 +113,6 @@ export default class CartModuleService
|
||||
this.lineItemTaxLineService_ = lineItemTaxLineService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
private shouldIncludeTotals(config: FindConfig<any>): boolean {
|
||||
const totalFields = [
|
||||
"total",
|
||||
|
||||
Reference in new issue
Block a user