-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Refactor Medusa module and service patterns #71
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
Conversation
WalkthroughThe changes refactor a Medusa module example by introducing a constant for the module name, switching to a default export using this constant, and removing a previous named export. The service example is expanded with a model import and a custom method. A section on module registration in the configuration file is also added. Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant MedusaConfig
participant Module
participant MyService
participant Model
Developer->>Module: Define MY_MODULE constant
Module->>MyService: Extend MedusaService with Model
MyService->>Model: Import Model
MyService->>MyService: Add custom business logic method
Module-->>Module: Export as default using MY_MODULE
MedusaConfig->>Module: Register module in modules array
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
.cursor/rules/medusa-development.mdc (3)
41-46: Add the missingMyServiceimport to keep the snippet self-containedThe example introduces
MY_MODULEand immediately usesMyService, butMyServiceisn’t imported in this snippet. Readers who copy/paste will hit a TS/ES lint error.import { Module } from "@medusajs/framework/utils" +import MyService from "./services/my-service" export const MY_MODULE = "my-module" export default Module(MY_MODULE, { service: MyService, })
48-60: Tighten the service example – repository accessor and missing types
this.myModelRepository_is unlikely the correct accessor.
Medusa’s code-gen convention exposesthis.myModelRepository(no trailing underscore).CustomInput/CustomOutputare referenced but not imported or declared, which may confuse newcomers.// You can add custom methods here - async customMethod(data: CustomInput): Promise<CustomOutput> { - return await this.myModelRepository_.customQuery(data) + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + async customMethod(data: /* CustomInput */ unknown) { + return this.myModelRepository.customQuery(data) }Consider adding a brief note or inline type placeholder so the snippet compiles out-of-the-box.
64-79: Clarify the module path to reduce copy-paste frictionMost projects place Medusa modules under
apps/medusa/src/modules.
Adjusting the path in the snippet aligns it with the file-structure section farther below and avoids “cannot resolve module” errors.- resolve: "./src/modules/my-module", + // relative to the project root + resolve: "./apps/medusa/src/modules/my-module",Alternatively, preface with a short comment that the path should be updated to match the user’s workspace layout.
Summary by CodeRabbit