Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modules-sdk,link-modules,orchestration,inventory,product,stock-location): link modules #4637

Closed
wants to merge 21 commits into from

Conversation

carlos-r-l-rodrigues
Copy link
Contributor

What:
Default package containing all Medusa's link modules definition and manage the creation of pre-defined or custom links.

import { initialize as iniInventory } from "@medusajs/inventory";
import { initialize as iniProduct } from "@medusajs/product";

import {
  initialize as iniLinks,
  runMigrations as migrateLinks
} from "@medusajs/link-modules";

await Promise.all([iniInventory(), iniProduct()]);


await migrateLinks(); // create tables based on previous loaded modules

await iniLinks(); // load link based on previous loaded modules

await iniLinks(undefined, [
  {
    serviceName: "product_custom_translation_service_link",
    isLink: true,
    tableName: "product_transalations",
    alias: [
      {
        name: "translations",
      },
    ],
    primaryKeys: ["id", "product_id", "translation_id"],
    relationships: [
      {
        serviceName: Modules.PRODUCT,
        primaryKey: "id",
        foreignKey: "product_id",
        alias: "product",
      },
      {
        serviceName: "custom_translation_service",
        primaryKey: "id",
        foreignKey: "translation_id",
        alias: "transalation",
        deleteCascade: true,
      },
    ],
    extends: [
      {
        serviceName: Modules.PRODUCT,
        relationship: {
          serviceName: "product_custom_translation_service_link",
          primaryKey: "product_id",
          foreignKey: "id",
          alias: "translations",
          isList: true,
        },
      },
      {
        serviceName: "custom_translation_service",
        relationship: {
          serviceName: "product_custom_translation_service_link",
          primaryKey: "product_id",
          foreignKey: "id",
          alias: "product_link",
        },
      },
    ],
  },
]); // custom links

@changeset-bot
Copy link

changeset-bot bot commented Jul 30, 2023

🦋 Changeset detected

Latest commit: 25a9edc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@medusajs/stock-location Minor
@medusajs/orchestration Minor
@medusajs/link-modules Minor
@medusajs/modules-sdk Minor
@medusajs/inventory Minor
@medusajs/product Minor
@medusajs/medusa Minor
@medusajs/types Minor
@medusajs/utils Minor
@medusajs/workflows Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jul 31, 2023 1:00am

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 I am stopping the review here as I just saw that it wasn't ready sorry man. Let's huddle if needed

},
"dependencies": {
"@medusajs/modules-sdk": "^1.8.8",
"@medusajs/types": "^1.8.11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: dev deps

Comment on lines +10 to +15
{
name: "product_variant_inventory_item",
},
{
name: "product_variant_inventory_items",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: duplicate

Comment on lines +20 to +26
serviceName: Modules.PRODUCT,
primaryKey: "id",
foreignKey: "variant_id",
alias: "variant",
args: {
methodSuffix: "Variants",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: shouldn't it be a list of variants on which we retrieve and attach the inventory item?

import { getLoaders } from "../loaders"
import { getMigration } from "../migration"

type ILinkModule = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: we should change that no?


if (definition.relationships?.length !== 2 && !definition.isReadOnlyLink) {
throw new Error(
`Link module ${definition.serviceName} must have 2 relationships.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: shouldn't it be at least and not strict? unless it has 2 relationships and then the rest is just the extends?

config: FindConfig<unknown> = {},
sharedContext?: Context
): Promise<[ProductTypes.ProductDTO[], number]> {
const [products, count] = await this.pivotService_.listAndCount(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: rename the const to something more generic

}

@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
async create(data: unknown[], @MedusaContext() sharedContext: Context = {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: create a protected method such as create_ that is wrapped in a transaction and call it here, then call the serialize from the base repository on the result. Otherwise here we are returning a mikro orm object

productIds: string[],
@MedusaContext() sharedContext: Context = {}
): Promise<TPivot[]> {
return await this.pivotService_.softDelete(productIds, sharedContext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: same as previous

productIds: string[],
@MedusaContext() sharedContext: Context = {}
): Promise<TPivot[]> {
return await this.pivotService_.restore(productIds, sharedContext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: sam as previous

@@ -0,0 +1,97 @@
import { Context, DAL, FindConfig } from "@medusajs/types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: this file, missing all the decorators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants