Skip to content

Commit

Permalink
add directory images
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Nov 29, 2024
1 parent bf94841 commit 3fcfca1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Learn more about API route validation in [this chapter](../../../advanced-develo

You create a validation schema in a `validators.{ts,js}` file under a sub-directory of the `src/api` directory. So, create the file `src/api/admin/brands/validators.ts` with the following content:

![Directory structure of Medusa application after adding validators file](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869806/Medusa%20Book/brand-route-dir-overview-1_yfyjss.jpg)

```ts title="src/api/admin/brands/validators.ts"
import { z } from "zod"

Expand All @@ -59,6 +61,8 @@ Learn more about API routes [in this guide](../../../basics/api-routes/page.mdx)

The route's path is the path of `route.{ts,js}` relative to `src/api`. So, to create the API route at `/admin/brands`, create the file `src/api/admin/brands/route.ts` with the following content:

![Directory structure of the Medusa application after adding the route](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869882/Medusa%20Book/brand-route-dir-overview-2_hjqlnf.jpg)

```ts title="src/api/admin/brands/route.ts"
import {
MedusaRequest,
Expand Down Expand Up @@ -115,6 +119,8 @@ Medusa provides a `validateAndTransformBody` middleware that accepts a Zod valid

Middlewares are defined in the special file `src/api/middlewares.ts`. So, to add the validation middleware on the API route you created in the previous step, create the file `src/api/middlewares.ts` with the following content:

![Directory structure of the Medusa application after adding the middleware](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869977/Medusa%20Book/brand-route-dir-overview-3_kcx511.jpg)

```ts title="src/api/middlewares.ts"
import {
defineMiddlewares,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Learn more about modules in [this chapter](../../../basics/modules/page.mdx).

Modules are created in a sub-directory of `src/modules`. So, start by creating the directory `src/modules/brand` that will hold the Brand Module's files.

![Directory structure in Medusa project after adding the brand directory](https://res.cloudinary.com/dza7lstvk/image/upload/v1732868844/Medusa%20Book/brand-dir-overview-1_hxwvgx.jpg)

---

## 2. Create Data Model
Expand All @@ -34,6 +36,8 @@ Learn more about data models in [this chapter](../../../basics/modules/page.mdx#

You create a data model in a TypeScript or JavaScript file under the `models` directory of a module. So, to create a data model that represents a new `brand` table in the database, create the file `src/modules/brand/models/brand.ts` with the following content:

![Directory structure in module after adding the brand data model](https://res.cloudinary.com/dza7lstvk/image/upload/v1732868920/Medusa%20Book/brand-dir-overview-2_lexhdl.jpg)

```ts title="src/modules/brand/models/brand.ts"
import { model } from "@medusajs/framework/utils"

Expand Down Expand Up @@ -72,6 +76,8 @@ Learn more about services in [this chapter](../../../basics/modules/page.mdx#2-c

You define a service in a `service.ts` or `service.js` file at the root of your module's directory. So, create the file `src/modules/brand/service.ts` with the following content:

![Directory structure in module after adding the service](https://res.cloudinary.com/dza7lstvk/image/upload/v1732868984/Medusa%20Book/brand-dir-overview-3_jo7baj.jpg)

export const serviceHighlights = [
["4", "MedusaService", "A service factory that generates data-management methods."]
]
Expand Down Expand Up @@ -109,6 +115,8 @@ A module must export a definition that tells Medusa the name of the module and i

So, to export the Brand Module's definition, create the file `src/modules/brand/index.ts` with the following content:

![Directory structure in module after adding the definition file](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869045/Medusa%20Book/brand-dir-overview-4_nf8ymw.jpg)

```ts title="src/modules/brand/index.ts"
import { Module } from "@medusajs/framework/utils"
import BrandModuleService from "./service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ A workflow consists of a series of steps, each step created in a TypeScript or J

The workflow you're creating in this guide has one step to create the brand. So, create the file `src/workflows/create-brand/steps/create-brand.ts` with the following content:

![Directory structure in the Medusa project after adding the file for createBrandStep](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869184/Medusa%20Book/brand-workflow-dir-overview-1_fjvf5j.jpg)

```ts title="src/workflows/create-brand/steps/create-brand.ts"
import {
createStep,
Expand Down Expand Up @@ -122,6 +124,8 @@ You can now create the workflow that runs the `createBrandStep`. A workflow is c

So, create the file `src/workflows/create-brand/index.ts` with the following content:

![Directory structure in the Medusa project after adding the file for createBrandWorkflow](https://res.cloudinary.com/dza7lstvk/image/upload/v1732869424/Medusa%20Book/brand-workflow-dir-overview-2_cbotxb.jpg)

```ts
import {
createWorkflow,
Expand Down

0 comments on commit 3fcfca1

Please sign in to comment.