feat(cart): GET /store/carts/:id (#6262)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const cartModuleService: ICartModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.CART
|
||||
)
|
||||
|
||||
// TODO: Replace with remoteQuery
|
||||
const cart = await cartModuleService.retrieve(req.params.id, {
|
||||
select: req.retrieveConfig.select,
|
||||
relations: req.retrieveConfig.relations,
|
||||
})
|
||||
|
||||
// const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
// const variables = { id: req.params.id }
|
||||
|
||||
// const query = {
|
||||
// cart: {
|
||||
// __args: variables,
|
||||
// ...defaultStoreCartRemoteQueryObject,
|
||||
// },
|
||||
// }
|
||||
|
||||
// const [cart] = await remoteQuery(query)
|
||||
|
||||
res.json({ cart })
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { transformQuery } from "../../../api/middlewares"
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import * as QueryConfig from "./query-config"
|
||||
import { StoreGetCartsCartParams } from "./validators"
|
||||
|
||||
export const storeCartRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/store/carts/:id",
|
||||
middlewares: [
|
||||
transformQuery(
|
||||
StoreGetCartsCartParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,64 @@
|
||||
export const defaultStoreCartFields = [
|
||||
"id",
|
||||
"currency_code",
|
||||
"email",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
]
|
||||
|
||||
export const defaultStoreCartRelations = [
|
||||
"items",
|
||||
"shipping_address",
|
||||
"billing_address",
|
||||
"shipping_methods",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultStoreCartFields,
|
||||
defaultRelations: defaultStoreCartRelations,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const defaultStoreCartRemoteQueryObject = {
|
||||
fields: defaultStoreCartFields,
|
||||
line_items: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"title",
|
||||
"quantity",
|
||||
"unit_price",
|
||||
],
|
||||
},
|
||||
shipping_address: {
|
||||
fields: [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"address_1",
|
||||
"address_2",
|
||||
"city",
|
||||
"postal_code",
|
||||
"country_code",
|
||||
"region_code",
|
||||
"phone",
|
||||
],
|
||||
},
|
||||
billing_address: {
|
||||
fields: [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"address_1",
|
||||
"address_2",
|
||||
"city",
|
||||
"postal_code",
|
||||
"country_code",
|
||||
"region_code",
|
||||
"phone",
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { FindParams } from "../../../types/common"
|
||||
|
||||
export class StoreGetCartsCartParams extends FindParams {}
|
||||
Reference in New Issue
Block a user