docs: update endpoints to use file-routing approach (#5397)

- Move the original guides for creating endpoints and middlewares to sub-sections in the Endpoints category.
- Replace existing guides for endpoints and middlewares with the new approach.
- Update all endpoints-related snippets across docs to use this new approach.
This commit is contained in:
Shahed Nasser
2023-10-19 15:56:26 +00:00
committed by GitHub
parent b38f73726d
commit c28935b4e8
170 changed files with 3658 additions and 3344 deletions
@@ -83,32 +83,35 @@ After that, you can add your custom methods to the repository. In the example ab
## Step 3: Use Your Extended Repository
You can now use your extended repository in other resources such as services or endpoints.
You can now use your extended repository in other resources such as services or API Routes.
Heres an example of using it in an endpoint:
Heres an example of using it in an API Route:
```ts
```ts title=src/api/store/custom/route.ts
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import ProductRepository from "./path/to/product.ts"
import EntityManager from "@medusajs/medusa"
import { EntityManager } from "typeorm"
export default () => {
export const GET = async (
req: MedusaRequest,
res: MedusaResponse
) => {
// ...
router.get("/custom-endpoint", (req, res) => {
// ...
const productRepository: typeof ProductRepository =
req.scope.resolve(
"productRepository"
)
const manager: EntityManager = req.scope.resolve("manager")
const productRepo = manager.withRepository(
productRepository
)
productRepo.customFunction()
const productRepository: typeof ProductRepository =
req.scope.resolve(
"productRepository"
)
const manager: EntityManager = req.scope.resolve("manager")
const productRepo = manager.withRepository(
productRepository
)
productRepo.customFunction()
// ...
})
// ...
}
```