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 authored and GitHub committed 2024-07-05 13:00:40 +00:00
1 parent eafa3560ae
commit b368251ca3
99 files changed
+1267 -488

No files matched your search

@@ -9,9 +9,13 @@ import {
} from "../__fixtures__/product"
import { IProductModuleService, ProductDTO } from "@medusajs/types"
import { kebabCase, Modules, ProductStatus } from "@medusajs/utils"
import { kebabCase, Module, Modules, ProductStatus } from "@medusajs/utils"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { ProductCategoryService, ProductService } from "@services"
import {
ProductCategoryService,
ProductModuleService,
ProductService,
} from "@services"
import { moduleIntegrationTestRunner } from "medusa-test-utils"
import {
categoriesData,
@@ -37,6 +41,94 @@ moduleIntegrationTestRunner<Service>({
categoryService = moduleService.productCategoryService_
})
it(`should export the appropriate linkable configuration`, () => {
const linkable = Module(Modules.PRODUCT, {
service: ProductModuleService,
}).linkable
expect(Object.keys(linkable)).toEqual([
"product",
"productVariant",
"productOption",
"productType",
"productImage",
"productTag",
"productCollection",
"productCategory",
])
Object.keys(linkable).forEach((key) => {
delete linkable[key].toJSON
})
expect(linkable).toEqual({
product: {
id: {
linkable: "product_id",
primaryKey: "id",
serviceName: "productService",
field: "product",
},
},
productVariant: {
id: {
linkable: "product_variant_id",
primaryKey: "id",
serviceName: "productService",
field: "productVariant",
},
},
productOption: {
id: {
linkable: "product_option_id",
primaryKey: "id",
serviceName: "productService",
field: "productOption",
},
},
productType: {
id: {
linkable: "product_type_id",
primaryKey: "id",
serviceName: "productService",
field: "productType",
},
},
productImage: {
id: {
linkable: "product_image_id",
primaryKey: "id",
serviceName: "productService",
field: "productImage",
},
},
productTag: {
id: {
linkable: "product_tag_id",
primaryKey: "id",
serviceName: "productService",
field: "productTag",
},
},
productCollection: {
id: {
linkable: "product_collection_id",
primaryKey: "id",
serviceName: "productService",
field: "productCollection",
},
},
productCategory: {
id: {
linkable: "product_category_id",
primaryKey: "id",
serviceName: "productService",
field: "productCategory",
},
},
})
})
describe("Product Service", () => {
let testManager: SqlEntityManager
let products!: Product[]
+1 -5
View File
@@ -47,14 +47,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",
"lodash": "^4.17.21"
"awilix": "^8.0.0"
}
}
+3 -4
View File
@@ -1,7 +1,6 @@
import { ModuleExports } from "@medusajs/types"
import { Module, Modules } from "@medusajs/utils"
import { ProductModuleService } from "@services"
const moduleDefinition: ModuleExports = {
export default Module(Modules.PRODUCT, {
service: ProductModuleService,
}
export default moduleDefinition
})
+20 -43
View File
@@ -1,56 +1,33 @@
import { defineJoinerConfig, Modules } from "@medusajs/utils"
import {
Product,
ProductCategory,
ProductCollection,
ProductOption,
ProductTag,
ProductType,
ProductVariant,
} from "@models"
import ProductImage from "./models/product-image"
export const joinerConfig = defineJoinerConfig(Modules.PRODUCT, {
models: [
Product,
ProductVariant,
ProductOption,
ProductType,
ProductImage,
ProductTag,
ProductCollection,
ProductCategory,
],
primaryKeys: ["id", "handle"],
// This module provides more alias than the default config builder
alias: [
{
name: ["product", "products"],
args: {
entity: "Product",
},
},
{
name: ["product_variant", "product_variants", "variant", "variants"],
args: {
entity: "ProductVariant",
},
},
{
name: ["product_option", "product_options"],
args: {
entity: "ProductOption",
},
},
{
name: ["product_type", "product_types"],
args: {
entity: "ProductType",
},
},
{
name: ["product_image", "product_images"],
args: {
entity: "ProductImage",
},
},
{
name: ["product_tag", "product_tags"],
args: {
entity: "ProductTag",
},
},
{
name: ["product_collection", "product_collections"],
args: {
entity: "ProductCollection",
},
},
{
name: ["product_category", "product_categories"],
args: {
entity: "ProductCategory",
},
},
],
})