chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-03 17:36:38 +03:00
1 parent 224ebb2154
commit 4fe28f5a95
6187 files changed
+601447 -598226

No files matched your search

@@ -0,0 +1,19 @@
export const metadata = {
title: `Stock Location Concepts`,
}
# {metadata.title}
In this document, you’ll learn about the main concepts in the Stock Location Module, and how data is stored and related.
## Stock Location
A stock location, represented by the `StockLocation` data model, represents a location where stock items are kept. For example, a warehouse.
The `InventoryLevel` and `ReservationItem` data models of the Inventory Module are associated with the `StockLocation` to provide inventory details per location. Learn more about this relation in [this guide](../relations-to-other-modules/page.mdx).
---
## StockLocationAddress
The `StockLocationAddress` data model belongs to the `StockLocation` data model. It provides more detailed information of the location, such as country code or street address.
@@ -0,0 +1,257 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Examples of the Stock Location Module`,
}
# {metadata.title}
In this document, you’ll find common examples of how you can use the Stock Location Module in your application.
## Create a Stock Location
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
const stockLocation = await stockLocationModuleService.create(
{
name: request.body.name,
}
)
res.json({
stock_location: stockLocation,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeStockLocationModule,
} from "@medusajs/stock-location-next"
export async function POST(request: Request) {
const stockLocationModuleService =
await initializeStockLocationModule({})
const body = await request.json()
const stockLocation = await stockLocationModuleService.create(
{
name: body.name,
}
)
return NextResponse.json({ stock_location: stockLocation })
}
```
</CodeTab>
</CodeTabs>
---
## List Stock Locations
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
res.json({
stock_locations: await stockLocationModuleService.list({}),
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeStockLocationModule,
} from "@medusajs/stock-location-next"
export async function GET(request: Request) {
const stockLocationModuleService =
await initializeStockLocationModule({})
return NextResponse.json({
stock_locations: await stockLocationModuleService.list({}),
})
}
```
</CodeTab>
</CodeTabs>
---
## Add Address to Stock Location
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
const stockLocation = await stockLocationModuleService.update(
{
id: request.params.id,
address: {
country_code: request.body.country_code,
city: request.body.city,
address_1: request.body.address_1,
postal_code: request.body.postal_code,
},
}
)
res.json({
stock_location: stockLocation,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeStockLocationModule,
} from "@medusajs/stock-location-next"
type ContextType = {
params: {
id: string
}
}
export async function POST(
request: Request,
{ params }: ContextType
) {
const stockLocationModuleService =
await initializeStockLocationModule({})
const body = await request.json()
const stockLocation = await stockLocationModuleService.update(
{
id: params.id,
address: {
country_code: body.country_code,
city: body.city,
address_1: body.address_1,
postal_code: body.postal_code,
},
}
)
return NextResponse.json({
stock_location: stockLocation,
})
}
```
</CodeTab>
</CodeTabs>
---
## Delete a Stock Location
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function DELETE(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
await stockLocationModuleService.delete(request.params.id)
res.status(200)
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeStockLocationModule,
} from "@medusajs/stock-location-next"
type ContextType = {
params: {
id: string
}
}
export async function DELETE(
request: Request,
{ params }: ContextType
) {
const stockLocationModuleService =
await initializeStockLocationModule({})
await stockLocationModuleService.delete(params.id)
}
```
</CodeTab>
</CodeTabs>
---
## More Examples
The [module interface reference](/references/stock-location) provides a reference to all the methods available for use with examples for each.
@@ -0,0 +1,136 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Stock Location Module`,
}
# {metadata.title}
The Stock Location Module is the `@medusajs/stock-location-next` NPM package that provides stock-location-related features in your Medusa and Node.js applications.
It's mainly useful with the [Inventory Module](../inventory/page.mdx).
<Note>
This module is an updated version of the [Stock Location Module part of the multi-warehouse feature](../../modules/multiwarehouse/stock-location-module.md). In Medusa V2, the previous version of the module will no longer be in use.
</Note>
## Features
### Stock Location Management
Store and manage stock locations. Stock locations can be associated with other models that require a location, such as the [Inventory Module's InventoryLevel](../inventory/concepts/page.mdx#inventory-level).
```ts
const stockLocation = await stockLocationModuleService.create(
{
name: "Warehouse 1",
}
)
```
### Address Management
A stock location can have detailed address details.
```ts
const stockLocation = await stockLocationModuleService.update(
{
id: "sloc_123",
address: {
country_code: "US",
city: "New York City",
address_1: "52 Stone St",
postal_code: "10004",
},
}
)
```
---
## Configure Stock Location Module
After installing the `@medusajs/stock-location` package in your Medusa application, add it to the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const modules = {
// ...
stockLocationService: {
resolve: "@medusajs/stock-location-next",
},
}
```
---
## How to Use Stock Location Module's Service
You can use the Stock Location Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STOCK_LOCATION` imported from `@medusajs/modules-sdk`.
For example:
<CodeTabs groupId="resource-type">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
res.json({
stock_locations: await stockLocationModuleService.list({}),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const stockLocationModuleService: IStockLocationService =
container.resolve(ModuleRegistrationName.STOCK_LOCATION)
const stockLocations = await stockLocationModuleService.list(
{}
)
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const stockLocationModuleService: IStockLocationService =
context.container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const stockLocations = await stockLocationModuleService.list(
{}
)
})
```
</CodeTab>
</CodeTabs>
@@ -0,0 +1,17 @@
export const metadata = {
title: `Relations between Stock Location Module and Other Modules`,
}
# {metadata.title}
When Commerce Modules are used together in a Medusa application, the Medusa application handles building the relations between these modules.
This document showcases the relation between the Stock Location Module and other Commerce Modules.
## Inventory Module
Reservation items and inventory items are associated with a location. The Medusa application forms a relation between the `ReservationItem` and `StockLocation` data models, and the `InventoryLevel` and `StockLocation` data models.
![A diagram showcasing an example of how resources from the Stock Location and Inventory modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709716521/Medusa%20Resources/stock-location-inventory_logsrt.jpg)
With this relation, stock and reserved quantity is specific to a location, providing you with more flexibility. The location can be as simple as having only a name, and more flexible by adding more address details to it.