feat(medusa): Use remote query in get cart API route (#6285)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { LINKS } from "../links"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
export const CartSalesChannel: ModuleJoinerConfig = {
|
||||
serviceName: LINKS.CartSalesChannel,
|
||||
@@ -21,14 +21,12 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
||||
relationships: [
|
||||
{
|
||||
serviceName: Modules.CART,
|
||||
isInternalService: true,
|
||||
primaryKey: "id",
|
||||
foreignKey: "cart_id",
|
||||
alias: "cart",
|
||||
},
|
||||
{
|
||||
serviceName: Modules.SALES_CHANNEL,
|
||||
isInternalService: true,
|
||||
primaryKey: "id",
|
||||
foreignKey: "sales_channel_id",
|
||||
alias: "sales_channel",
|
||||
@@ -42,7 +40,6 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
||||
},
|
||||
relationship: {
|
||||
serviceName: LINKS.CartSalesChannel,
|
||||
isInternalService: true,
|
||||
primaryKey: "cart_id",
|
||||
foreignKey: "id",
|
||||
alias: "sales_channel_link",
|
||||
@@ -55,7 +52,6 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
||||
},
|
||||
relationship: {
|
||||
serviceName: LINKS.CartSalesChannel,
|
||||
isInternalService: true,
|
||||
primaryKey: "sales_channel_id",
|
||||
foreignKey: "id",
|
||||
alias: "cart_link",
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { defaultStoreCartRemoteQueryObject } from "../query-config"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const cartModuleService: ICartModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.CART
|
||||
)
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
// TODO: Replace with remoteQuery
|
||||
const cart = await cartModuleService.retrieve(req.params.id, {
|
||||
select: req.retrieveConfig.select,
|
||||
relations: req.retrieveConfig.relations,
|
||||
})
|
||||
const variables = { id: req.params.id }
|
||||
|
||||
// const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
const query = {
|
||||
cart: {
|
||||
__args: variables,
|
||||
...defaultStoreCartRemoteQueryObject,
|
||||
},
|
||||
}
|
||||
|
||||
// const variables = { id: req.params.id }
|
||||
|
||||
// const query = {
|
||||
// cart: {
|
||||
// __args: variables,
|
||||
// ...defaultStoreCartRemoteQueryObject,
|
||||
// },
|
||||
// }
|
||||
|
||||
// const [cart] = await remoteQuery(query)
|
||||
const [cart] = await remoteQuery(query)
|
||||
|
||||
res.json({ cart })
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export const retrieveTransformQueryConfig = {
|
||||
|
||||
export const defaultStoreCartRemoteQueryObject = {
|
||||
fields: defaultStoreCartFields,
|
||||
line_items: {
|
||||
items: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
|
||||
import { Cart } from "../models"
|
||||
|
||||
export default {
|
||||
serviceName: "cartService",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: { cart_id: "Cart" },
|
||||
alias: {
|
||||
name: ["cart", "carts"],
|
||||
args: { entity: Cart.name },
|
||||
},
|
||||
relationships: [
|
||||
{
|
||||
serviceName: Modules.PRODUCT,
|
||||
primaryKey: "id",
|
||||
foreignKey: "variant_id",
|
||||
alias: "variant",
|
||||
args: {
|
||||
methodSuffix: "Variants",
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceName: "regionService",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
alias: "region",
|
||||
},
|
||||
{
|
||||
serviceName: "customerService",
|
||||
primaryKey: "id",
|
||||
foreignKey: "customer_id",
|
||||
alias: "customer",
|
||||
},
|
||||
],
|
||||
} as ModuleJoinerConfig
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
|
||||
export default {
|
||||
serviceName: "customerService",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: { customer_id: "Customer" },
|
||||
alias: [
|
||||
{
|
||||
name: "customer",
|
||||
},
|
||||
{
|
||||
name: "customers",
|
||||
},
|
||||
],
|
||||
} as ModuleJoinerConfig
|
||||
@@ -1,6 +1,3 @@
|
||||
export * as cart from "./cart-service"
|
||||
export * as customer from "./customer-service"
|
||||
export * as publishableApiKey from "./publishable-api-key-service"
|
||||
export * as region from "./region-service"
|
||||
export * as shippingProfile from "./shipping-profile-service"
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
|
||||
export default {
|
||||
serviceName: "orderService",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: { order_id: "Order" },
|
||||
alias: [
|
||||
{
|
||||
name: "order",
|
||||
},
|
||||
{
|
||||
name: "orders",
|
||||
},
|
||||
],
|
||||
} as ModuleJoinerConfig
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
|
||||
export default {
|
||||
serviceName: "regionService",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: { region_id: "Region" },
|
||||
alias: [
|
||||
{
|
||||
name: "region",
|
||||
},
|
||||
{
|
||||
name: "regions",
|
||||
},
|
||||
],
|
||||
} as ModuleJoinerConfig
|
||||
Reference in New Issue
Block a user