docs: fix code block titles (#5733)

* docs: fix code block titles

* remove console

* fix build error
This commit is contained in:
Shahed Nasser
2023-11-27 16:08:10 +00:00
committed by GitHub
parent de8f748674
commit 547b16ead5
110 changed files with 483 additions and 456 deletions
@@ -17,7 +17,7 @@ To create a service, create a TypeScript or JavaScript file in `src/services` to
For example, if you want to create a service `PostService`, eventually registered as `postService`, create the file `post.ts` in `src/services` with the following content:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import { TransactionBaseService } from "@medusajs/medusa"
class PostService extends TransactionBaseService {
@@ -53,7 +53,7 @@ As the service extends the `TransactionBaseService` class, all resources registe
So, if you want your service to use another service, add it as part of your constructors dependencies and set it to a field inside your services class:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import { ProductService } from "@medusajs/medusa"
import { PostRepository } from "../repositories/post"
@@ -70,7 +70,7 @@ class PostService extends TransactionBaseService {
Then, you can use that service anywhere in your custom service. For example:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
class PostService extends TransactionBaseService {
// ...
async getProductCount() {
@@ -91,7 +91,7 @@ However, to actually get an instance of the repository within the service's meth
For example:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import { PostRepository } from "../repositories/post"
class PostService extends TransactionBaseService {
@@ -131,7 +131,7 @@ The data returned by the function passed as a parameter to the `atomicPhase_` me
For example, the `PostService`'s `create` method with the `atomicPhase_` method:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
class PostService extends TransactionBaseService {
protected postRepository_: typeof PostRepository
// ...
@@ -169,7 +169,7 @@ There are three lifetime types:
You can set the lifetime of your service by setting the `LIFE_TIME` static property:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import { TransactionBaseService } from "@medusajs/medusa"
import { Lifetime } from "awilix"
@@ -188,7 +188,7 @@ Within your service, you may need to access the Medusa configuration exported fr
For example:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import {
ConfigModule,
TransactionBaseService,
@@ -228,7 +228,7 @@ The `@medusajs/medusa` package also provides a `buildQuery` method that allows y
So, for example, to create a method that retrieves a list of posts and the total number of posts available:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import {
FindConfig,
Selector,
@@ -260,7 +260,7 @@ In addition, you can expand relations when retrieving a single item with the hel
For example, to create a method that retrieves a single post:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import {
FindConfig,
TransactionBaseService,
@@ -319,7 +319,7 @@ This assumes you're handling errors in your custom API Route as explained [here]
For example:
```ts title=src/services/post.ts
```ts title="src/services/post.ts"
import { MedusaError } from "@medusajs/utils"
class PostService extends TransactionBaseService {