feat(medusa): Use remote query in get cart API route (#6285)
This commit is contained in:
1 parent
2cebadc3a8
commit
d5e4707084
8 files changed
+12
-112
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
import { LINKS } from "../links"
|
import { LINKS } from "../links"
|
||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
|
|
||||||
export const CartSalesChannel: ModuleJoinerConfig = {
|
export const CartSalesChannel: ModuleJoinerConfig = {
|
||||||
serviceName: LINKS.CartSalesChannel,
|
serviceName: LINKS.CartSalesChannel,
|
||||||
@@ -21,14 +21,12 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
|||||||
relationships: [
|
relationships: [
|
||||||
{
|
{
|
||||||
serviceName: Modules.CART,
|
serviceName: Modules.CART,
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "id",
|
primaryKey: "id",
|
||||||
foreignKey: "cart_id",
|
foreignKey: "cart_id",
|
||||||
alias: "cart",
|
alias: "cart",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
serviceName: Modules.SALES_CHANNEL,
|
serviceName: Modules.SALES_CHANNEL,
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "id",
|
primaryKey: "id",
|
||||||
foreignKey: "sales_channel_id",
|
foreignKey: "sales_channel_id",
|
||||||
alias: "sales_channel",
|
alias: "sales_channel",
|
||||||
@@ -42,7 +40,6 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
|||||||
},
|
},
|
||||||
relationship: {
|
relationship: {
|
||||||
serviceName: LINKS.CartSalesChannel,
|
serviceName: LINKS.CartSalesChannel,
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "cart_id",
|
primaryKey: "cart_id",
|
||||||
foreignKey: "id",
|
foreignKey: "id",
|
||||||
alias: "sales_channel_link",
|
alias: "sales_channel_link",
|
||||||
@@ -55,7 +52,6 @@ export const CartSalesChannel: ModuleJoinerConfig = {
|
|||||||
},
|
},
|
||||||
relationship: {
|
relationship: {
|
||||||
serviceName: LINKS.CartSalesChannel,
|
serviceName: LINKS.CartSalesChannel,
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "sales_channel_id",
|
primaryKey: "sales_channel_id",
|
||||||
foreignKey: "id",
|
foreignKey: "id",
|
||||||
alias: "cart_link",
|
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 { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||||
|
import { defaultStoreCartRemoteQueryObject } from "../query-config"
|
||||||
|
|
||||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||||
const cartModuleService: ICartModuleService = req.scope.resolve(
|
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||||
ModuleRegistrationName.CART
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: Replace with remoteQuery
|
const variables = { id: req.params.id }
|
||||||
const cart = await cartModuleService.retrieve(req.params.id, {
|
|
||||||
select: req.retrieveConfig.select,
|
|
||||||
relations: req.retrieveConfig.relations,
|
|
||||||
})
|
|
||||||
|
|
||||||
// const remoteQuery = req.scope.resolve("remoteQuery")
|
const query = {
|
||||||
|
cart: {
|
||||||
|
__args: variables,
|
||||||
|
...defaultStoreCartRemoteQueryObject,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// const variables = { id: req.params.id }
|
const [cart] = await remoteQuery(query)
|
||||||
|
|
||||||
// const query = {
|
|
||||||
// cart: {
|
|
||||||
// __args: variables,
|
|
||||||
// ...defaultStoreCartRemoteQueryObject,
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const [cart] = await remoteQuery(query)
|
|
||||||
|
|
||||||
res.json({ cart })
|
res.json({ cart })
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ export const retrieveTransformQueryConfig = {
|
|||||||
|
|
||||||
export const defaultStoreCartRemoteQueryObject = {
|
export const defaultStoreCartRemoteQueryObject = {
|
||||||
fields: defaultStoreCartFields,
|
fields: defaultStoreCartFields,
|
||||||
line_items: {
|
items: {
|
||||||
fields: [
|
fields: [
|
||||||
"id",
|
"id",
|
||||||
"created_at",
|
"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 publishableApiKey from "./publishable-api-key-service"
|
||||||
export * as region from "./region-service"
|
|
||||||
export * as shippingProfile from "./shipping-profile-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