chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions
@@ -50,12 +50,11 @@ const draftOrder = await orderModuleService.createOrders({
Apply promotions or discounts to the order's items and shipping methods by adding adjustment lines that are factored into their subtotals.
```ts
const lineAdjustments =
await orderModuleService.addLineItemAdjustments({
item_id: "cali_123",
code: "50OFF",
amount: 500,
})
const lineAdjustments = await orderModuleService.addLineItemAdjustments({
item_id: "cali_123",
code: "50OFF",
amount: 500,
})
const shippingAdjustments =
await orderModuleService.addShippingMethodAdjustments({
@@ -78,10 +77,9 @@ Orders can be changed to return items from the customer, exchange an item with a
Changes are only applied after confirmation, and order history is preserved through versioning.
```ts
const orderChange =
await orderModuleService.createOrderChange({
order_id: "ord_123",
})
const orderChange = await orderModuleService.createOrderChange({
order_id: "ord_123",
})
// add item to the order
await orderModuleService.addOrderAction({
@@ -109,60 +107,57 @@ 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 { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const orderModuleService: IOrderModuleService =
req.scope.resolve(ModuleRegistrationName.ORDER)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const orderModuleService: IOrderModuleService = req.scope.resolve(
ModuleRegistrationName.ORDER
)
res.json({
orders: await orderModuleService.listOrders(),
})
}
```
res.json({
orders: await orderModuleService.listOrders(),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const orderModuleService: IOrderModuleService =
container.resolve(ModuleRegistrationName.ORDER)
export default async function subscriberHandler({ container }: SubscriberArgs) {
const orderModuleService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
const orders = await orderModuleService.listOrders()
}
```
const orders = await orderModuleService.listOrders()
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
const step1 = createStep(
"step-1",
async (_, { container }) => {
const orderModuleService: IOrderModuleService =
container.resolve(
ModuleRegistrationName.ORDER
)
const orders = await orderModuleService.listOrders()
})
```
const step1 = createStep("step-1", async (_, { container }) => {
const orderModuleService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
const orders = await orderModuleService.listOrders()
})
```
</CodeTab>
</CodeTabs>