feat(dashboard): shipping management (#6995)

**What**
- shipping flow
- shipping profile pages
- delete fulfillment set endpoint
- delete shipping profile endpoint
This commit is contained in:
Frane Polić
2024-04-16 13:42:56 +00:00
committed by GitHub
parent c3260a2c5a
commit 0a9b9b073d
62 changed files with 2501 additions and 12 deletions
@@ -0,0 +1,40 @@
import {
AdminFulfillmentSetsDeleteResponse,
IFulfillmentModuleService,
} from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { deleteFulfillmentSetsWorkflow } from "@medusajs/core-flows"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../types/routing"
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse<AdminFulfillmentSetsDeleteResponse>
) => {
const { id } = req.params
const fulfillmentModuleService = req.scope.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
// Test if exists
await fulfillmentModuleService.retrieve(id)
const { errors } = await deleteFulfillmentSetsWorkflow(req.scope).run({
input: { ids: [id] },
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({
id,
object: "fulfillment_set",
deleted: true,
})
}
@@ -32,6 +32,11 @@ export const adminFulfillmentSetsRoutesMiddlewares: MiddlewareRoute[] = [
matcher: "/admin/fulfillment-sets/:id/service-zones/:zone_id",
middlewares: [],
},
{
method: ["DELETE"],
matcher: "/admin/fulfillment-sets/:id",
middlewares: [],
},
{
method: ["POST"],
matcher: "/admin/fulfillment-sets/:id/service-zones/:zone_id",
@@ -1,4 +1,10 @@
import { AdminShippingProfileResponse } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
AdminShippingProfileDeleteResponse,
AdminShippingProfileResponse,
IFulfillmentModuleService,
} from "@medusajs/types"
import { deleteShippingProfileWorkflow } from "@medusajs/core-flows"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
@@ -24,3 +30,32 @@ export const GET = async (
res.status(200).json({ shipping_profile: shippingProfile })
}
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse<AdminShippingProfileDeleteResponse>
) => {
const { id } = req.params
const fulfillmentModuleService = req.scope.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
// Test if exists
await fulfillmentModuleService.retrieveShippingProfile(id)
const { errors } = await deleteShippingProfileWorkflow(req.scope).run({
input: { ids: [id] },
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({
id,
object: "shipping_profile",
deleted: true,
})
}