Files
medusa-store/www/apps/book/app/cheatsheet/page.mdx
T
Shahed Nasser bb0303cd6a docs: improvements to module and data model documentation (#8062)
* docs: improvements to module and data model documentation

* add note about data model name casing
2024-07-11 13:53:40 +03:00

160 lines
4.7 KiB
Plaintext

import { Table } from "docs-ui"
export const metadata = {
title: `${pageNumber} Cheat sheet`,
}
# {metadata.title}
This chapter provides a cheat sheet for Medusa's resources on when to use or not use them.
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Use if</Table.HeaderCell>
<Table.HeaderCell>Don't use if</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body className="[&_td]:align-top [&_td]:pt-1 [&_td:first-child]:font-bold">
<Table.Row>
<Table.Cell>API Routes</Table.Cell>
<Table.Cell>
- You're exposing custom functionality to be used in the admin dashboard or an external application, such as a storefront.
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Modules</Table.Cell>
<Table.Cell>
- You're implementing a custom commerce feature. For example, you're implementing digital products.
- You want to extend data models in other commerce modules, such as adding a field or a relation to the Product model.
- You want to re-use your custom commerce functionalities across Medusa applications or use them in other environments, such as Edge functions and Next.js apps.
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Module Links</Table.Cell>
<Table.Cell>
- You want to create a relation between data models from different modules.
</Table.Cell>
<Table.Cell>
- You want to create a relationship between data models in the same module. Use data model relationships instead.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Data Models</Table.Cell>
<Table.Cell>
- You want to store data related to your customization in the database.
</Table.Cell>
<Table.Cell>
- You want to store simple key-value pairs related to a Medusa data model. Instead, use the `metadata` field that models have, which is an object of custom key-value pairs.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Data Model Relationships</Table.Cell>
<Table.Cell>
- You want to create a relation between data models in the same module.
</Table.Cell>
<Table.Cell>
- You want to create a relationship between data models in different modules. Use module links instead.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Loaders</Table.Cell>
<Table.Cell>
- You're performing an action at application start-up.
- You're establishing a one-time connection with an external system.
</Table.Cell>
<Table.Cell>
- You want to perform an action continuously or at a set time pattern in the application. Use scheduled jobs instead.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Subscribers</Table.Cell>
<Table.Cell>
- You want to perform an action everytime a specific event is emitted in the Medusa application.
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Scheduled Jobs</Table.Cell>
<Table.Cell>
- You're executing an action at a specified time interval during application runtime.
- The action must be executed automatically.
</Table.Cell>
<Table.Cell>
- You want the action to execute at a specified time interval while the Medusa application **isn't** running. Instead, use the operating system's equivalent of a cron job.
- You want to execute the action once. Use loaders instead.
- You want to execute the action if an event occurs. Use subscribers instead.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Workflows</Table.Cell>
<Table.Cell>
- You're defining a flow with interactions across multiple systems and services.
- You're defining flows to be used across different resources. For example, if you want to invoke the flow manually through an API Router, but also want to automate its running through a scheduled job.
- You want to define how the series of actions are rolled-back when an error occurs.
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Middlewares</Table.Cell>
<Table.Cell>
- You want to protect API routes by a custom condition.
- You're modifying the request body.
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>