chore: rename route from api-v2 to api (#7379)
* chore: rename route from api-v2 to api * chore: change oas references * chore: remove v2 ref
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { refetchOrder } from "../helpers"
|
||||
import { StoreGetOrdersParamsType } from "../validators"
|
||||
|
||||
// TODO: Do we want to apply some sort of authentication here? My suggestion is that we do
|
||||
export const GET = async (
|
||||
req: MedusaRequest<StoreGetOrdersParamsType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const order = await refetchOrder(
|
||||
req.params.id,
|
||||
req.scope,
|
||||
req.remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
res.json({ order })
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import { refetchEntity } from "../../utils/refetch-entity"
|
||||
|
||||
export const refetchOrder = async (
|
||||
idOrFilter: string | object,
|
||||
scope: MedusaContainer,
|
||||
fields: string[]
|
||||
) => {
|
||||
return await refetchEntity("order", idOrFilter, scope, fields)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import { authenticate } from "../../../utils/middlewares/authenticate-middleware"
|
||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||
import * as QueryConfig from "./query-config"
|
||||
import { StoreGetOrderParams, StoreGetOrdersParams } from "./validators"
|
||||
|
||||
export const storeOrderRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/store/orders",
|
||||
middlewares: [
|
||||
authenticate("store", ["session", "bearer"]),
|
||||
validateAndTransformQuery(
|
||||
StoreGetOrdersParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/store/orders/:id",
|
||||
middlewares: [
|
||||
authenticate("store", ["session", "bearer"], {
|
||||
allowUnauthenticated: true,
|
||||
}),
|
||||
validateAndTransformQuery(
|
||||
StoreGetOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
// TODO: This is copied over from admin. Scope what fields and relations are allowed for store
|
||||
|
||||
export const defaultStoreOrderFields = [
|
||||
"id",
|
||||
"status",
|
||||
"version",
|
||||
"summary",
|
||||
"metadata",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
export const defaultStoreRetrieveOrderFields = [
|
||||
"id",
|
||||
"status",
|
||||
"version",
|
||||
"summary",
|
||||
"currency_code",
|
||||
"total",
|
||||
"subtotal",
|
||||
"tax_total",
|
||||
"discount_total",
|
||||
"discount_tax_total",
|
||||
"original_total",
|
||||
"original_tax_total",
|
||||
"item_total",
|
||||
"item_subtotal",
|
||||
"item_tax_total",
|
||||
"original_item_total",
|
||||
"original_item_subtotal",
|
||||
"original_item_tax_total",
|
||||
"shipping_total",
|
||||
"shipping_subtotal",
|
||||
"shipping_tax_total",
|
||||
"original_shipping_tax_total",
|
||||
"original_shipping_tax_subtotal",
|
||||
"original_shipping_total",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"*items",
|
||||
"*items.tax_lines",
|
||||
"*items.adjustments",
|
||||
"*items.detail",
|
||||
"*items.variant",
|
||||
"*items.variant.product",
|
||||
"*shipping_address",
|
||||
"*billing_address",
|
||||
"*shipping_methods",
|
||||
"*shipping_methods.tax_lines",
|
||||
"*shipping_methods.adjustments",
|
||||
"*payment_collections",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaults: defaultStoreRetrieveOrderFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaults: defaultStoreOrderFields,
|
||||
isList: false,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import { AdminGetOrdersParamsType } from "../../admin/draft-orders/validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order",
|
||||
variables: {
|
||||
filters: { ...req.filterableFields, customer_id: req.auth.actor_id },
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { z } from "zod"
|
||||
import { createFindParams, createSelectParams } from "../../utils/validators"
|
||||
|
||||
export const StoreGetOrderParams = createSelectParams()
|
||||
export type StoreGetOrderParamsType = z.infer<typeof StoreGetOrderParams>
|
||||
|
||||
export const StoreGetOrdersParams = createFindParams({
|
||||
offset: 0,
|
||||
limit: 50,
|
||||
}).merge(
|
||||
z.object({
|
||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
status: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
$and: z.lazy(() => StoreGetOrdersParams.array()).optional(),
|
||||
$or: z.lazy(() => StoreGetOrdersParams.array()).optional(),
|
||||
})
|
||||
)
|
||||
export type StoreGetOrdersParamsType = z.infer<typeof StoreGetOrdersParams>
|
||||
Reference in New Issue
Block a user