Skip to content

Commit

Permalink
docs: add details on updating a cart's customer (#10226)
Browse files Browse the repository at this point in the history
Should be merged after releasing v2.0.5

Closes DX-1096
  • Loading branch information
shahednasser authored Nov 25, 2024
1 parent 01b0a84 commit ae1c607
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const GET = async (
const b = req.validatedQuery.b as number

res.json({
sum: a + b
sum: a + b,
})
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class HelloModuleService {
data: {
id: "123",
// other data payload
}
},
})
}
}
Expand All @@ -167,18 +167,18 @@ export const depsHighlight = [
]

```ts title="medusa-config.ts" highlights={depsHighlight}
import { Modules } from '@medusajs/framework/utils'
import { Modules } from "@medusajs/framework/utils"

module.exports = defineConfig({
// ...
modules: [
{
resolve: "./src/modules/hello",
dependencies: [
Modules.EVENT_BUS
]
}
]
Modules.EVENT_BUS,
],
},
],
})
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const { data: productCustoms } = await query.graph({
take: 5,
skip: 0,
},
});
})
```

In the object passed to the `graph` method:
Expand Down Expand Up @@ -318,9 +318,9 @@ export default defineMiddlewares({
defaults: [
"id",
"name",
"products.*"
"products.*",
],
isList: true
isList: true,
}
),
],
Expand Down Expand Up @@ -371,7 +371,7 @@ export const GET = async (

const { data: myCustoms } = await query.graph({
entity: "my_custom",
...req.remoteQueryConfig
...req.remoteQueryConfig,
})

res.json({ my_customs: myCustoms })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const myWorkflow = createWorkflow(
const today = new Date()

return new WorkflowResponse({
today
today,
})
})

Expand All @@ -117,7 +117,7 @@ const myWorkflow = createWorkflow(
const today = transform({}, () => new Date())

return new WorkflowResponse({
today
today,
})
})
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Each workflow step must have a unique ID, which is the ID passed as a first para

```ts
const useQueryGraphStep = createStep(
"use-query-graph",
"use-query-graph"
// ...
)
```
Expand All @@ -29,13 +29,13 @@ const helloWorkflow = createWorkflow(
() => {
const { data: products } = useQueryGraphStep({
entity: "product",
fields: ["id"]
fields: ["id"],
})

// ERROR OCCURS HERE: A STEP HAS THE SAME ID AS ANOTHER IN THE WORKFLOW
const { data: customers } = useQueryGraphStep({
entity: "customer",
fields: ["id"]
fields: ["id"],
})
}
)
Expand Down Expand Up @@ -63,13 +63,13 @@ const helloWorkflow = createWorkflow(
() => {
const { data: products } = useQueryGraphStep({
entity: "product",
fields: ["id"]
fields: ["id"],
})

// ✓ No error occurs, the step has a different ID.
const { data: customers } = useQueryGraphStep({
entity: "customer",
fields: ["id"]
fields: ["id"],
}).config({ name: "fetch-customers" })
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default async function orderPlacedHandler({
await sendOrderConfirmationWorkflow(container)
.run({
input: {
id: data.id
}
id: data.id,
},
})
}

Expand Down
24 changes: 12 additions & 12 deletions www/apps/book/app/learn/basics/loaders/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export const loaderHighlights = [

```ts title="src/modules/mongo/loaders/connection.ts" highlights={loaderHighlights}
import { LoaderOptions } from "@medusajs/framework/types"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { asValue } from "awilix";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
import { asValue } from "awilix"
import { MongoClient } from "mongodb"

type ModuleOptions = {
Expand All @@ -144,7 +144,7 @@ type ModuleOptions = {

export default async function mongoConnectionLoader({
container,
options
options,
}: LoaderOptions<ModuleOptions>) {
if (!options.connection_url) {
throw new Error(`[MONGO MDOULE]: connection_url option is required.`)
Expand Down Expand Up @@ -187,10 +187,10 @@ module.exports = defineConfig({
resolve: "./src/modules/mongo",
options: {
connection_url: process.env.MONGO_CONNECTION_URL,
db_name: process.env.MONGO_DB_NAME
}
}
]
db_name: process.env.MONGO_DB_NAME,
},
},
],
})
```

Expand Down Expand Up @@ -239,11 +239,11 @@ export default class MongoModuleService {
const moviesCol = this.mongoClient_.collection("movie")

const insertedMovie = await moviesCol.insertOne({
title
title,
})

const movie = await moviesCol.findOne({
_id: insertedMovie.insertedId
_id: insertedMovie.insertedId,
})

return movie
Expand All @@ -254,8 +254,8 @@ export default class MongoModuleService {

await moviesCol.deleteOne({
_id: {
equals: id
}
equals: id,
},
})
}
}
Expand All @@ -274,7 +274,7 @@ export const MONGO_MODULE = "mongo"

export default Module(MONGO_MODULE, {
service: MongoModuleService,
loaders: [mongoConnectionLoader]
loaders: [mongoConnectionLoader],
})
```

Expand Down
28 changes: 14 additions & 14 deletions www/apps/book/app/learn/basics/medusa-container/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const highlights = [
]

```ts highlights={highlights}
import { MedusaRequest, MedusaResponse } from "@medusajs/framework";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { MedusaRequest, MedusaResponse } from "@medusajs/framework"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"

export async function GET(
req: MedusaRequest,
Expand All @@ -41,12 +41,12 @@ export async function GET(
entity: "product",
fields: ["*"],
filters: {
id: "prod_123"
}
id: "prod_123",
},
})

res.json({
products
products,
})
}
```
Expand Down Expand Up @@ -84,7 +84,7 @@ export const subscriberHighlights = [

```ts highlights={subscriberHighlights}
import { SubscriberArgs, type SubscriberConfig } from "@medusajs/framework"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"

export default async function productCreateHandler({
event: { data },
Expand All @@ -96,8 +96,8 @@ export default async function productCreateHandler({
entity: "product",
fields: ["*"],
filters: {
id: data.id
}
id: data.id,
},
})

console.log(`You created a product with the title ${products[0].title}`)
Expand All @@ -119,7 +119,7 @@ export const scheduledJobHighlights = [

```ts highlights={scheduledJobHighlights}
import { MedusaContainer } from "@medusajs/framework/types"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"

export default async function myCustomJob(
container: MedusaContainer
Expand All @@ -130,8 +130,8 @@ export default async function myCustomJob(
entity: "product",
fields: ["*"],
filters: {
id: "prod_123"
}
id: "prod_123",
},
})

console.log(
Expand Down Expand Up @@ -160,7 +160,7 @@ import {
createStep,
StepResponse,
} from "@medusajs/framework/workflows-sdk"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"

const step1 = createStep("step-1", async (_, { container }) => {
const query = container.resolve(ContainerRegistrationKeys.QUERY)
Expand All @@ -169,8 +169,8 @@ const step1 = createStep("step-1", async (_, { container }) => {
entity: "product",
fields: ["*"],
filters: {
id: "prod_123"
}
id: "prod_123",
},
})

return new StepResponse(products)
Expand Down
36 changes: 18 additions & 18 deletions www/apps/book/app/learn/basics/modules/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { model } from "@medusajs/framework/utils"

const Post = model.define("post", {
id: model.id().primaryKey(),
title: model.text()
title: model.text(),
})

export default Post
Expand Down Expand Up @@ -143,8 +143,8 @@ module.exports = defineConfig({
},
modules: [
{
resolve: "./src/modules/blog"
}
resolve: "./src/modules/blog",
},
],
})
```
Expand All @@ -168,16 +168,16 @@ npx medusa db:generate blog
The `db:generate` command of the Medusa CLI accepts one or more module names to generate the migration for. It will create a migration file for the Blog Module in the directory `src/modules/blog/migrations` similar to the following:

```ts
import { Migration } from '@mikro-orm/migrations';
import { Migration } from "@mikro-orm/migrations"

export class Migration20241121103722 extends Migration {

async up(): Promise<void> {
this.addSql('create table if not exists "post" ("id" text not null, "title" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "post_pkey" primary key ("id"));');
this.addSql("create table if not exists \"post\" (\"id\" text not null, \"title\" text not null, \"created_at\" timestamptz not null default now(), \"updated_at\" timestamptz not null default now(), \"deleted_at\" timestamptz null, constraint \"post_pkey\" primary key (\"id\"));")
}

async down(): Promise<void> {
this.addSql('drop table if exists "post" cascade;');
this.addSql("drop table if exists \"post\" cascade;")
}

}
Expand Down Expand Up @@ -226,10 +226,10 @@ import {
createStep,
createWorkflow,
StepResponse,
WorkflowResponse
} from "@medusajs/framework/workflows-sdk";
import { BLOG_MODULE } from "../modules/blog";
import BlogModuleService from "../modules/blog/service";
WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"
import { BLOG_MODULE } from "../modules/blog"
import BlogModuleService from "../modules/blog/service"

type CreatePostWorkflowInput = {
title: string
Expand All @@ -241,7 +241,7 @@ const createPostStep = createStep(
const blogModuleService: BlogModuleService = container.resolve(BLOG_MODULE)

const post = await blogModuleService.createPosts({
title
title,
})

return new StepResponse(post, post)
Expand Down Expand Up @@ -272,11 +272,11 @@ You'll now execute that workflow in an API route to expose the feature of creati
```ts
import type {
MedusaRequest,
MedusaResponse
} from "@medusajs/framework/http";
MedusaResponse,
} from "@medusajs/framework/http"
import {
createPostWorkflow
} from "../../../workflows/create-post";
createPostWorkflow,
} from "../../../workflows/create-post"

export async function POST(
req: MedusaRequest,
Expand All @@ -285,12 +285,12 @@ export async function POST(
const { result: post } = await createPostWorkflow(req.scope)
.run({
input: {
title: "My Post"
}
title: "My Post",
},
})

res.json({
post
post,
})
}
```
Expand Down
Loading

0 comments on commit ae1c607

Please sign in to comment.