From 1b7ec0c5196eae1e1ba81bb2914505a01b6f9f4c Mon Sep 17 00:00:00 2001 From: Philip Korsholm Date: Wed, 5 Oct 2022 14:17:23 +0700 Subject: [PATCH] add expand and field params to medusa-react and medusa-js --- packages/medusa-js/src/resources/admin/orders.ts | 10 +++++++++- .../src/hooks/admin/orders/queries.ts | 15 +++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/medusa-js/src/resources/admin/orders.ts b/packages/medusa-js/src/resources/admin/orders.ts index 76c2a9edfd8cf..633b5ed08f831 100644 --- a/packages/medusa-js/src/resources/admin/orders.ts +++ b/packages/medusa-js/src/resources/admin/orders.ts @@ -16,6 +16,7 @@ import { AdminPostOrdersOrderSwapsSwapFulfillmentsReq, AdminPostOrdersOrderSwapsSwapShipmentsReq, } from "@medusajs/medusa" +import { FindParams } from "@medusajs/medusa/dist/types/common" import qs from "qs" import { ResponsePromise } from "../../typings" import BaseResource from "../base" @@ -32,9 +33,16 @@ class AdminOrdersResource extends BaseResource { retrieve( id: string, + query?: FindParams, customHeaders: Record = {} ): ResponsePromise { - const path = `/admin/orders/${id}` + let path = `/admin/orders/${id}` + + if (query) { + const queryString = qs.stringify(query) + path = `/admin/orders/${id}?${queryString}` + } + return this.client.request("GET", path, undefined, {}, customHeaders) } diff --git a/packages/medusa-react/src/hooks/admin/orders/queries.ts b/packages/medusa-react/src/hooks/admin/orders/queries.ts index 6d3808820cbe9..203d8ba9f65b4 100644 --- a/packages/medusa-react/src/hooks/admin/orders/queries.ts +++ b/packages/medusa-react/src/hooks/admin/orders/queries.ts @@ -4,6 +4,7 @@ import { AdminGetOrdersParams, } from "@medusajs/medusa" import { Response } from "@medusajs/medusa-js" +import { FindParams } from "@medusajs/medusa/dist/types/common" import { useQuery } from "react-query" import { useMedusa } from "../../../contexts" import { UseQueryOptionsWrapper } from "../../../types" @@ -11,7 +12,12 @@ import { queryKeysFactory } from "../../utils/index" const ADMIN_ORDERS_QUERY_KEY = `admin_orders` as const -export const adminOrderKeys = queryKeysFactory(ADMIN_ORDERS_QUERY_KEY) +export const adminOrderKeys = { + ...queryKeysFactory(ADMIN_ORDERS_QUERY_KEY), + detailOrder(id: string, query?: FindParams) { + return [...this.detail(id), { ...(query || {}) }] + } +} type OrderQueryKeys = typeof adminOrderKeys @@ -34,16 +40,17 @@ export const useAdminOrders = ( export const useAdminOrder = ( id: string, + query?: FindParams, options?: UseQueryOptionsWrapper< Response, Error, - ReturnType + ReturnType > ) => { const { client } = useMedusa() const { data, ...rest } = useQuery( - adminOrderKeys.detail(id), - () => client.admin.orders.retrieve(id), + adminOrderKeys.detailOrder(id, query), + () => client.admin.orders.retrieve(id, query), options ) return { ...data, ...rest } as const