docs: fix restaurant-delivery recipe after latest update (#11806)
This commit is contained in:
@@ -503,21 +503,22 @@ The workflow only has one step that creates a restaurant.
|
|||||||
To implement the step, create the file `src/workflows/restaurant/steps/create-restaurant.ts` with the following content:
|
To implement the step, create the file `src/workflows/restaurant/steps/create-restaurant.ts` with the following content:
|
||||||
|
|
||||||
export const createRestaurantHighlight = [
|
export const createRestaurantHighlight = [
|
||||||
["14", "createRestaurants", "Create the restaurant."],
|
["15", "createRestaurants", "Create the restaurant."],
|
||||||
["23", "deleteRestaurants", "Delete the restaurant if an error occurs in the workflow."]
|
["24", "deleteRestaurants", "Delete the restaurant if an error occurs in the workflow."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/workflows/restaurant/steps/create-restaurant.ts" highlights={createRestaurantHighlight} collapsibleLines="1-6" expandMoreLabel="Show Imports"
|
```ts title="src/workflows/restaurant/steps/create-restaurant.ts" highlights={createRestaurantHighlight} collapsibleLines="1-7" expandMoreLabel="Show Imports"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import {
|
import {
|
||||||
CreateRestaurantDTO,
|
CreateRestaurantDTO,
|
||||||
} from "../../../modules/restaurant/types/mutations"
|
} from "../../../modules/restaurant/types/mutations"
|
||||||
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
||||||
|
import RestaurantModuleService from "../../../modules/restaurant/service"
|
||||||
|
|
||||||
export const createRestaurantStep = createStep(
|
export const createRestaurantStep = createStep(
|
||||||
"create-restaurant-step",
|
"create-restaurant-step",
|
||||||
async function (data: CreateRestaurantDTO, { container }) {
|
async function (data: CreateRestaurantDTO, { container }) {
|
||||||
const restaurantModuleService = container.resolve(
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -526,7 +527,7 @@ export const createRestaurantStep = createStep(
|
|||||||
return new StepResponse(restaurant, restaurant.id)
|
return new StepResponse(restaurant, restaurant.id)
|
||||||
},
|
},
|
||||||
function (id: string, { container }) {
|
function (id: string, { container }) {
|
||||||
const restaurantModuleService = container.resolve(
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -755,6 +756,7 @@ To implement the first step, create the file `src/workflows/user/steps/create-re
|
|||||||
```ts title="src/workflows/user/steps/create-restaurant-admin.ts"
|
```ts title="src/workflows/user/steps/create-restaurant-admin.ts"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
||||||
|
import RestaurantModuleService from "../../../modules/restaurant/service"
|
||||||
|
|
||||||
export type CreateRestaurantAdminInput = {
|
export type CreateRestaurantAdminInput = {
|
||||||
restaurant_id: string;
|
restaurant_id: string;
|
||||||
@@ -769,7 +771,9 @@ export const createRestaurantAdminStep = createStep(
|
|||||||
data: CreateRestaurantAdminInput,
|
data: CreateRestaurantAdminInput,
|
||||||
{ container }
|
{ container }
|
||||||
) => {
|
) => {
|
||||||
const restaurantModuleService = container.resolve(RESTAURANT_MODULE)
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
|
RESTAURANT_MODULE
|
||||||
|
)
|
||||||
const restaurantAdmin = await restaurantModuleService.createRestaurantAdmins(
|
const restaurantAdmin = await restaurantModuleService.createRestaurantAdmins(
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
@@ -781,9 +785,10 @@ export const createRestaurantAdminStep = createStep(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const service = container.resolve(RESTAURANT_MODULE)
|
const restaurantModuleService: RestaurantModuleService =
|
||||||
|
container.resolve(RESTAURANT_MODULE)
|
||||||
|
|
||||||
await service.deleteRestaurantAdmins(id)
|
await restaurantModuleService.deleteRestaurantAdmins(id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -797,8 +802,8 @@ Then, to implement the step that creates a driver, create the file `src/workflow
|
|||||||
|
|
||||||
```ts title="src/workflows/user/steps/create-driver.ts"
|
```ts title="src/workflows/user/steps/create-driver.ts"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
|
||||||
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../../modules/delivery/service"
|
||||||
|
|
||||||
export type CreateDriverInput = {
|
export type CreateDriverInput = {
|
||||||
email: string;
|
email: string;
|
||||||
@@ -814,7 +819,9 @@ export const createDriverStep = createStep(
|
|||||||
data: CreateDriverInput,
|
data: CreateDriverInput,
|
||||||
{ container }
|
{ container }
|
||||||
) => {
|
) => {
|
||||||
const deliveryModuleService = container.resolve(DELIVERY_MODULE)
|
const deliveryModuleService: DeliveryModuleService = container.resolve(
|
||||||
|
DELIVERY_MODULE
|
||||||
|
)
|
||||||
|
|
||||||
const driver = await deliveryModuleService.createDrivers(data)
|
const driver = await deliveryModuleService.createDrivers(data)
|
||||||
|
|
||||||
@@ -825,9 +832,11 @@ export const createDriverStep = createStep(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const service = container.resolve(RESTAURANT_MODULE)
|
const deliveryModuleService: DeliveryModuleService = container.resolve(
|
||||||
|
DELIVERY_MODULE
|
||||||
|
)
|
||||||
|
|
||||||
await service.deleteRestaurantAdmins(id)
|
await deliveryModuleService.deleteDrivers(id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
@@ -1098,11 +1107,12 @@ import {
|
|||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
||||||
import { DeleteRestaurantAdminWorkflow } from "../workflows/delete-restaurant-admin"
|
import { DeleteRestaurantAdminWorkflow } from "../workflows/delete-restaurant-admin"
|
||||||
|
import RestaurantModuleService from "../../../modules/restaurant/service"
|
||||||
|
|
||||||
export const deleteRestaurantAdminStep = createStep(
|
export const deleteRestaurantAdminStep = createStep(
|
||||||
"delete-restaurant-admin",
|
"delete-restaurant-admin",
|
||||||
async ({ id }: DeleteRestaurantAdminWorkflow, { container }) => {
|
async ({ id }: DeleteRestaurantAdminWorkflow, { container }) => {
|
||||||
const restaurantModuleService = container.resolve(
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1113,7 +1123,7 @@ export const deleteRestaurantAdminStep = createStep(
|
|||||||
return new StepResponse(undefined, { admin })
|
return new StepResponse(undefined, { admin })
|
||||||
},
|
},
|
||||||
async ({ admin }, { container }) => {
|
async ({ admin }, { container }) => {
|
||||||
const restaurantModuleService = container.resolve(
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1442,6 +1452,7 @@ import {
|
|||||||
createStep,
|
createStep,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
import { RESTAURANT_MODULE } from "../../../modules/restaurant"
|
||||||
|
import RestaurantModuleService from "../../../modules/restaurant/service"
|
||||||
|
|
||||||
type ValidateRestaurantStepInput = {
|
type ValidateRestaurantStepInput = {
|
||||||
restaurant_id: string
|
restaurant_id: string
|
||||||
@@ -1450,7 +1461,7 @@ type ValidateRestaurantStepInput = {
|
|||||||
export const validateRestaurantStep = createStep(
|
export const validateRestaurantStep = createStep(
|
||||||
"validate-restaurant",
|
"validate-restaurant",
|
||||||
async ({ restaurant_id }: ValidateRestaurantStepInput, { container }) => {
|
async ({ restaurant_id }: ValidateRestaurantStepInput, { container }) => {
|
||||||
const restaurantModuleService = container.resolve(
|
const restaurantModuleService: RestaurantModuleService = container.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1469,31 +1480,35 @@ This step tries to retrieve the restaurant using the Restaurant Module’s main
|
|||||||
Next, create the file `src/workflows/delivery/steps/create-delivery.ts` with the following content to create the second step:
|
Next, create the file `src/workflows/delivery/steps/create-delivery.ts` with the following content to create the second step:
|
||||||
|
|
||||||
export const createDeliveryStepHighlights = [
|
export const createDeliveryStepHighlights = [
|
||||||
["9", "createDeliveries", "Create the delivery."],
|
["11", "createDeliveries", "Create the delivery."],
|
||||||
["18", "softDeleteDeliveries", "Delete the delivery if an error occurs in the workflow."]
|
["21", "softDeleteDeliveries", "Delete the delivery if an error occurs in the workflow."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/workflows/delivery/steps/create-delivery.ts" highlights={createDeliveryStepHighlights}
|
```ts title="src/workflows/delivery/steps/create-delivery.ts" highlights={createDeliveryStepHighlights}
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../../modules/delivery/service"
|
||||||
|
|
||||||
export const createDeliveryStep = createStep(
|
export const createDeliveryStep = createStep(
|
||||||
"create-delivery-step",
|
"create-delivery-step",
|
||||||
async function (_, { container }) {
|
async function (_, { container }) {
|
||||||
const service = container.resolve(DELIVERY_MODULE)
|
const deliverModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
const delivery = await service.createDeliveries()
|
const delivery = await deliverModuleService.createDeliveries({})
|
||||||
|
|
||||||
return new StepResponse(delivery, {
|
return new StepResponse(delivery, {
|
||||||
delivery_id: delivery.id,
|
delivery_id: delivery.id,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async function ({ delivery_id }, { container }) {
|
async function ({ delivery_id }, { container }) {
|
||||||
const service = container.resolve(DELIVERY_MODULE)
|
const deliverModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
service.softDeleteDeliveries(delivery_id)
|
deliverModuleService.softDeleteDeliveries(delivery_id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This step creates a delivery and returns it. In the compensation function, it deletes the delivery.
|
This step creates a delivery and returns it. In the compensation function, it deletes the delivery.
|
||||||
@@ -1672,20 +1687,26 @@ You’ll implement these steps next.
|
|||||||
Create the file `src/workflows/delivery/steps/set-transaction-id.ts` with the following content:
|
Create the file `src/workflows/delivery/steps/set-transaction-id.ts` with the following content:
|
||||||
|
|
||||||
export const setTransactionIdStepHighlights = [
|
export const setTransactionIdStepHighlights = [
|
||||||
["9", "updateDeliveries", "Update the delivery with the workflow's transaction ID."],
|
["15", "updateDeliveries", "Update the delivery with the workflow's transaction ID."],
|
||||||
["19", "updateDeliveries", "Update the delivery to remove the transaction ID if an error occurs."]
|
["26", "updateDeliveries", "Update the delivery to remove the transaction ID if an error occurs."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/workflows/delivery/steps/set-transaction-id.ts" highlights={setTransactionIdStepHighlights}
|
```ts title="src/workflows/delivery/steps/set-transaction-id.ts" highlights={setTransactionIdStepHighlights}
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../../modules/delivery/service"
|
||||||
|
|
||||||
|
export type SetTransactionIdStepInput = {
|
||||||
|
delivery_id: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const setTransactionIdStep = createStep(
|
export const setTransactionIdStep = createStep(
|
||||||
"create-delivery-step",
|
"create-delivery-step",
|
||||||
async function (deliveryId: string, { container, context }) {
|
async function (deliveryId: string, { container, context }) {
|
||||||
const service = container.resolve(DELIVERY_MODULE)
|
const deliverModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
const delivery = await service.updateDeliveries({
|
const delivery = await deliverModuleService.updateDeliveries({
|
||||||
id: deliveryId,
|
id: deliveryId,
|
||||||
transaction_id: context.transactionId,
|
transaction_id: context.transactionId,
|
||||||
})
|
})
|
||||||
@@ -1693,15 +1714,15 @@ export const setTransactionIdStep = createStep(
|
|||||||
return new StepResponse(delivery, delivery.id)
|
return new StepResponse(delivery, delivery.id)
|
||||||
},
|
},
|
||||||
async function (delivery_id: string, { container }) {
|
async function (delivery_id: string, { container }) {
|
||||||
const service = container.resolve(DELIVERY_MODULE)
|
const deliverModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
await service.updateDeliveries({
|
await deliverModuleService.updateDeliveries({
|
||||||
id: delivery_id,
|
id: delivery_id,
|
||||||
transaction_id: null,
|
transaction_id: null,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
In this step, you update the `transaction_id` property of the delivery to the current workflow execution’s transaction ID. It can be found in the `context` property passed in the second object parameter of the step.
|
In this step, you update the `transaction_id` property of the delivery to the current workflow execution’s transaction ID. It can be found in the `context` property passed in the second object parameter of the step.
|
||||||
@@ -2334,15 +2355,16 @@ The workflow has the following steps:
|
|||||||
So, start by creating the first step at `src/workflows/delivery/steps/update-delivery.ts`:
|
So, start by creating the first step at `src/workflows/delivery/steps/update-delivery.ts`:
|
||||||
|
|
||||||
export const updateDeliveryStepHighlights = [
|
export const updateDeliveryStepHighlights = [
|
||||||
["14", "prevDeliveryData", "Retrieve the previous data of the delivery for the compensation."],
|
["16", "prevDeliveryData", "Retrieve the previous data of the delivery for the compensation."],
|
||||||
["17", "updateDeliveries", "Update the delivery."],
|
["19", "updateDeliveries", "Update the delivery."],
|
||||||
["27", "updateDeliveries", "Update the delivery with the old data if an error occurs in the workflow."]
|
["35", "updateDeliveries", "Update the delivery with the old data if an error occurs in the workflow."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/workflows/delivery/steps/update-delivery.ts" highlights={updateDeliveryStepHighlights}
|
```ts title="src/workflows/delivery/steps/update-delivery.ts" highlights={updateDeliveryStepHighlights}
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../modules/delivery"
|
||||||
import { UpdateDelivery } from "../../../modules/delivery/types"
|
import { UpdateDelivery } from "../../../modules/delivery/types"
|
||||||
|
import DeliveryModuleService from "../../../modules/delivery/service"
|
||||||
|
|
||||||
type UpdateDeliveryStepInput = {
|
type UpdateDeliveryStepInput = {
|
||||||
data: UpdateDelivery;
|
data: UpdateDelivery;
|
||||||
@@ -2351,11 +2373,12 @@ type UpdateDeliveryStepInput = {
|
|||||||
export const updateDeliveryStep = createStep(
|
export const updateDeliveryStep = createStep(
|
||||||
"update-delivery-step",
|
"update-delivery-step",
|
||||||
async function ({ data }: UpdateDeliveryStepInput, { container }) {
|
async function ({ data }: UpdateDeliveryStepInput, { container }) {
|
||||||
const deliveryService = container.resolve(DELIVERY_MODULE)
|
const deliveryModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
const prevDeliveryData = await deliveryService.retrieveDelivery(data.id)
|
const prevDeliveryData = await deliveryModuleService.retrieveDelivery(data.id)
|
||||||
|
|
||||||
const delivery = await deliveryService
|
const delivery = await deliveryModuleService
|
||||||
.updateDeliveries([data])
|
.updateDeliveries([data])
|
||||||
.then((res) => res[0])
|
.then((res) => res[0])
|
||||||
|
|
||||||
@@ -2364,11 +2387,15 @@ export const updateDeliveryStep = createStep(
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
async ({ prevDeliveryData }, { container }) => {
|
async ({ prevDeliveryData }, { container }) => {
|
||||||
const deliveryService = container.resolve(DELIVERY_MODULE)
|
const deliverModuleService: DeliveryModuleService =
|
||||||
|
container.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
const { driver, ...prevDeliveryDataWithoutDriver } = prevDeliveryData
|
const {
|
||||||
|
driver,
|
||||||
|
...prevDeliveryDataWithoutDriver
|
||||||
|
} = prevDeliveryData
|
||||||
|
|
||||||
await deliveryService.updateDeliveries(prevDeliveryDataWithoutDriver)
|
await deliverModuleService.updateDeliveries(prevDeliveryDataWithoutDriver)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
@@ -2606,12 +2633,12 @@ The above API route should only be accessed by the admin of the restaurant assoc
|
|||||||
Start by creating the file `src/api/utils/is-delivery-restaurant.ts` with the following content:
|
Start by creating the file `src/api/utils/is-delivery-restaurant.ts` with the following content:
|
||||||
|
|
||||||
export const isDeliveryRestaurantHighlights = [
|
export const isDeliveryRestaurantHighlights = [
|
||||||
["21", "restaurantAdmin", "Retrieve the logged-in restaurant admin."],
|
["22", "restaurantAdmin", "Retrieve the logged-in restaurant admin."],
|
||||||
["28", "graph", "Retrieve the delivery based on the ID in the path parameter."],
|
["29", "graph", "Retrieve the delivery based on the ID in the path parameter."],
|
||||||
["40", "", "If the restaurant admin doesn't belong to the delivery's restaurant, return an unauthorized response."]
|
["41", "", "If the restaurant admin doesn't belong to the delivery's restaurant, return an unauthorized response."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/api/utils/is-delivery-restaurant.ts" highlights={isDeliveryRestaurantHighlights} collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
```ts title="src/api/utils/is-delivery-restaurant.ts" highlights={isDeliveryRestaurantHighlights} collapsibleLines="1-11" expandButtonLabel="Show Imports"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaNextFunction,
|
MedusaNextFunction,
|
||||||
@@ -2621,6 +2648,7 @@ import {
|
|||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { RESTAURANT_MODULE } from "../../modules/restaurant"
|
import { RESTAURANT_MODULE } from "../../modules/restaurant"
|
||||||
|
import RestaurantModuleService from "../../modules/restaurant/service"
|
||||||
|
|
||||||
export const isDeliveryRestaurant = async (
|
export const isDeliveryRestaurant = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
@@ -2628,7 +2656,7 @@ export const isDeliveryRestaurant = async (
|
|||||||
next: MedusaNextFunction
|
next: MedusaNextFunction
|
||||||
) => {
|
) => {
|
||||||
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
|
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
|
||||||
const restaurantModuleService = req.scope.resolve(
|
const restaurantModuleService: RestaurantModuleService = req.scope.resolve(
|
||||||
RESTAURANT_MODULE
|
RESTAURANT_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -3109,24 +3137,25 @@ The above route should only be accessed by the driver associated with the delive
|
|||||||
So, create the file `src/api/utils/is-delivery-driver.ts` holding the middleware function that performs the check:
|
So, create the file `src/api/utils/is-delivery-driver.ts` holding the middleware function that performs the check:
|
||||||
|
|
||||||
export const isDeliveryDriverHighlights = [
|
export const isDeliveryDriverHighlights = [
|
||||||
["17", "retrieveDelivery", "Retrieve the delivery using the ID in the path parameter."],
|
["18", "retrieveDelivery", "Retrieve the delivery using the ID in the path parameter."],
|
||||||
["24", "", "If the currently logged-in driver isn't associated with the delivery, return an unauthorized response."]
|
["25", "", "If the currently logged-in driver isn't associated with the delivery, return an unauthorized response."]
|
||||||
]
|
]
|
||||||
|
|
||||||
```ts title="src/api/utils/is-delivery-driver.ts" highlights={isDeliveryDriverHighlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
```ts title="src/api/utils/is-delivery-driver.ts" highlights={isDeliveryDriverHighlights} collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaNextFunction,
|
MedusaNextFunction,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { DELIVERY_MODULE } from "../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../modules/delivery/service"
|
||||||
|
|
||||||
export const isDeliveryDriver = async (
|
export const isDeliveryDriver = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse,
|
res: MedusaResponse,
|
||||||
next: MedusaNextFunction
|
next: MedusaNextFunction
|
||||||
) => {
|
) => {
|
||||||
const deliveryModuleService = req.scope.resolve(
|
const deliveryModuleService: DeliveryModuleService = req.scope.resolve(
|
||||||
DELIVERY_MODULE
|
DELIVERY_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -3298,7 +3327,7 @@ Before adding the storefront UI, you need an API route that allows a client to s
|
|||||||
|
|
||||||
So, create the file `src/api/deliveries/[id]/subscribe/route.ts` with the following content:
|
So, create the file `src/api/deliveries/[id]/subscribe/route.ts` with the following content:
|
||||||
|
|
||||||
```ts title="src/api/deliveries/[id]/subscribe/route.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports"
|
```ts title="src/api/deliveries/[id]/subscribe/route.ts" collapsibleLines="1-13" expandButtonLabel="Show Imports"
|
||||||
import {
|
import {
|
||||||
MedusaRequest,
|
MedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -3310,12 +3339,13 @@ import {
|
|||||||
handleDeliveryWorkflowId,
|
handleDeliveryWorkflowId,
|
||||||
} from "../../../../../workflows/delivery/workflows/handle-delivery"
|
} from "../../../../../workflows/delivery/workflows/handle-delivery"
|
||||||
import { DELIVERY_MODULE } from "../../../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../../../modules/delivery/service"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest,
|
req: MedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse
|
||||||
) => {
|
) => {
|
||||||
const deliveryModuleService = req.scope.resolve(
|
const deliveryModuleService: DeliveryModuleService = req.scope.resolve(
|
||||||
DELIVERY_MODULE
|
DELIVERY_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -3383,9 +3413,11 @@ Create the file `src/api/deliveries/[id]/route.ts` with the following content:
|
|||||||
```ts title="src/api/deliveries/[id]/route.ts"
|
```ts title="src/api/deliveries/[id]/route.ts"
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
import { DELIVERY_MODULE } from "../../../../modules/delivery"
|
import { DELIVERY_MODULE } from "../../../../modules/delivery"
|
||||||
|
import DeliveryModuleService from "../../../../modules/delivery/service"
|
||||||
|
|
||||||
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
||||||
const deliveryModuleService = req.scope.resolve(DELIVERY_MODULE)
|
const deliveryModuleService: DeliveryModuleService =
|
||||||
|
req.scope.resolve(DELIVERY_MODULE)
|
||||||
|
|
||||||
const delivery = await deliveryModuleService.retrieveDelivery(
|
const delivery = await deliveryModuleService.retrieveDelivery(
|
||||||
req.params.id
|
req.params.id
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ export const generatedEditDates = {
|
|||||||
"app/medusa-cli/commands/start/page.mdx": "2024-08-28T10:44:19.952Z",
|
"app/medusa-cli/commands/start/page.mdx": "2024-08-28T10:44:19.952Z",
|
||||||
"app/medusa-cli/commands/telemtry/page.mdx": "2025-01-16T09:51:24.323Z",
|
"app/medusa-cli/commands/telemtry/page.mdx": "2025-01-16T09:51:24.323Z",
|
||||||
"app/medusa-cli/commands/user/page.mdx": "2024-08-28T10:44:52.489Z",
|
"app/medusa-cli/commands/user/page.mdx": "2024-08-28T10:44:52.489Z",
|
||||||
"app/recipes/marketplace/examples/restaurant-delivery/page.mdx": "2025-02-24T13:31:26.838Z",
|
"app/recipes/marketplace/examples/restaurant-delivery/page.mdx": "2025-03-11T12:10:06.352Z",
|
||||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateCustomerGroup/page.mdx": "2024-12-09T13:21:33.569Z",
|
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateCustomerGroup/page.mdx": "2024-12-09T13:21:33.569Z",
|
||||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateReservation/page.mdx": "2024-12-09T13:21:34.505Z",
|
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateReservation/page.mdx": "2024-12-09T13:21:34.505Z",
|
||||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCustomerGroup/page.mdx": "2024-12-23T13:57:05.262Z",
|
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCustomerGroup/page.mdx": "2024-12-23T13:57:05.262Z",
|
||||||
|
|||||||
Reference in New Issue
Block a user