docs: fix code block titles (#5733)
* docs: fix code block titles * remove console * fix build error
This commit is contained in:
@@ -20,7 +20,7 @@ Entities can only be placed in the top level of the `src/models` directory. So,
|
||||
|
||||
:::
|
||||
|
||||
```ts title=src/models/post.ts
|
||||
```ts title="src/models/post.ts"
|
||||
import {
|
||||
BeforeInsert,
|
||||
Column,
|
||||
|
||||
@@ -33,7 +33,7 @@ In the file you created, you can import the entity you’re extending from the c
|
||||
|
||||
Here’s an example of extending the Product entity:
|
||||
|
||||
```ts title=src/models/product.ts
|
||||
```ts title="src/models/product.ts"
|
||||
import { Column, Entity } from "typeorm"
|
||||
import {
|
||||
// alias the core entity to not cause a naming conflict
|
||||
@@ -55,7 +55,7 @@ If you’re using JavaScript instead of TypeScript in your implementation, you c
|
||||
|
||||
To ensure that TypeScript is aware of your extended entity and affects the typing of the Medusa package itself, create the file `src/index.d.ts` with the following content:
|
||||
|
||||
```ts title=src/index.d.ts
|
||||
```ts title="src/index.d.ts"
|
||||
export declare module "@medusajs/medusa/dist/models/product" {
|
||||
declare interface Product {
|
||||
customAttribute: string;
|
||||
@@ -81,7 +81,7 @@ You can learn how to create or generate a migration in [this documentation](./mi
|
||||
|
||||
Here’s an example of a migration of the entity extended in this guide:
|
||||
|
||||
```ts title=src/migration/1680013376180-changeProduct.ts
|
||||
```ts title="src/migration/1680013376180-changeProduct.ts"
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
class changeProduct1680013376180 implements MigrationInterface {
|
||||
@@ -140,7 +140,7 @@ To change that and ensure your custom attribute is returned in your request, you
|
||||
|
||||
For example, if you added a custom attribute in the `Product` entity and you want to ensure it's returned in all the product's store API Routes (API Routes under the prefix `/store/products`), you can create a file under the `src/loaders` directory in your Medusa backend with the following content:
|
||||
|
||||
```ts title=src/loaders/extend-product-fields.ts
|
||||
```ts title="src/loaders/extend-product-fields.ts"
|
||||
export default async function () {
|
||||
const imports = (await import(
|
||||
"@medusajs/medusa/dist/api/routes/store/products/index"
|
||||
|
||||
@@ -39,7 +39,7 @@ A data source is Typeorm’s connection settings that allows you to connect to y
|
||||
|
||||
Here’s an example of the implementation of the extended Product repository:
|
||||
|
||||
```ts title=src/repositories/product.ts
|
||||
```ts title="src/repositories/product.ts"
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import {
|
||||
dataSource,
|
||||
@@ -87,7 +87,7 @@ You can now use your extended repository in other resources such as services or
|
||||
|
||||
Here’s an example of using it in an API Route:
|
||||
|
||||
```ts title=src/api/store/custom/route.ts
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
|
||||
@@ -22,7 +22,7 @@ If you haven't created a custom repository, you can access the default repositor
|
||||
|
||||
For example, to retrieve the default repository of an entity in a service:
|
||||
|
||||
```ts title=src/services/post.ts
|
||||
```ts title="src/services/post.ts"
|
||||
import { Post } from "../models/post"
|
||||
|
||||
class PostService extends TransactionBaseService {
|
||||
@@ -41,7 +41,7 @@ class PostService extends TransactionBaseService {
|
||||
|
||||
Another example is retrieving the default repository of an entity in an API Route:
|
||||
|
||||
```ts title=src/api/store/custom/route.ts
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -110,7 +110,7 @@ To access a custom repository within an API Route, use the `MedusaRequest` objec
|
||||
|
||||
For example:
|
||||
|
||||
```ts title=src/store/custom/route.ts
|
||||
```ts title="src/store/custom/route.ts"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -141,7 +141,7 @@ As custom repositories are registered in the [dependency container](../fundament
|
||||
|
||||
For example:
|
||||
|
||||
```ts title=src/services/post.ts
|
||||
```ts title="src/services/post.ts"
|
||||
import { PostRepository } from "../repositories/post"
|
||||
|
||||
class PostService extends TransactionBaseService {
|
||||
@@ -173,7 +173,7 @@ A subscriber handler function can resolve a repository using the `container` pro
|
||||
|
||||
For example:
|
||||
|
||||
```ts title=src/subscribers/post-handler.ts
|
||||
```ts title="src/subscribers/post-handler.ts"
|
||||
import {
|
||||
type SubscriberArgs,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
Reference in New Issue
Block a user