feat: Move shipping option + profile test and more (#7609)
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import {
|
||||
deleteShippingProfileWorkflow,
|
||||
updateShippingProfilesWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
AdminShippingProfileDeleteResponse,
|
||||
AdminShippingProfileResponse,
|
||||
IFulfillmentModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { deleteShippingProfileWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
import { AdminGetShippingProfileParamsType } from "../validators"
|
||||
import { refetchShippingProfile } from "../helpers"
|
||||
import {
|
||||
AdminGetShippingProfileParamsType,
|
||||
AdminUpdateShippingProfileType,
|
||||
} from "../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetShippingProfileParamsType>,
|
||||
@@ -48,3 +54,24 @@ export const DELETE = async (
|
||||
deleted: true,
|
||||
})
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateShippingProfileType>,
|
||||
res: MedusaResponse<AdminShippingProfileResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
await updateShippingProfilesWorkflow(req.scope).run({
|
||||
input: { selector: { id }, update: req.body },
|
||||
})
|
||||
|
||||
const shippingProfile = await refetchShippingProfile(
|
||||
req.params.id,
|
||||
req.scope,
|
||||
req.remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
res.status(200).json({
|
||||
shipping_profile: shippingProfile,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
AdminCreateShippingProfile,
|
||||
AdminGetShippingProfileParams,
|
||||
AdminGetShippingProfilesParams,
|
||||
AdminUpdateShippingProfile,
|
||||
} from "./validators"
|
||||
|
||||
export const adminShippingProfilesMiddlewares: MiddlewareRoute[] = [
|
||||
@@ -33,6 +34,17 @@ export const adminShippingProfilesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/shipping-profiles/:id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminUpdateShippingProfile),
|
||||
validateAndTransformQuery(
|
||||
AdminGetShippingProfileParams,
|
||||
retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/shipping-profiles/:id",
|
||||
|
||||
@@ -39,3 +39,14 @@ export const AdminCreateShippingProfile = z
|
||||
metadata: z.record(z.string(), z.unknown()).optional(),
|
||||
})
|
||||
.strict()
|
||||
|
||||
export type AdminUpdateShippingProfileType = z.infer<
|
||||
typeof AdminUpdateShippingProfile
|
||||
>
|
||||
export const AdminUpdateShippingProfile = z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
type: z.string().optional(),
|
||||
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
||||
})
|
||||
.strict()
|
||||
|
||||
Reference in New Issue
Block a user