From c626f0e3fe6072964bde382829e5735c88a59def Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 23 Dec 2024 17:25:50 +0200 Subject: [PATCH] fix(medusa,types): fix request query parameter types for store product routes --- .changeset/dull-chairs-whisper.md | 6 ++++ .../types/src/http/product/store/queries.ts | 34 +++++++++++-------- .../src/api/store/products/[id]/route.ts | 3 +- .../medusa/src/api/store/products/route.ts | 2 +- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 .changeset/dull-chairs-whisper.md diff --git a/.changeset/dull-chairs-whisper.md b/.changeset/dull-chairs-whisper.md new file mode 100644 index 0000000000000..bf08dac39daa7 --- /dev/null +++ b/.changeset/dull-chairs-whisper.md @@ -0,0 +1,6 @@ +--- +"@medusajs/types": patch +"@medusajs/medusa": patch +--- + +fix(medusa,types): fix request query parameter types for store product routes diff --git a/packages/core/types/src/http/product/store/queries.ts b/packages/core/types/src/http/product/store/queries.ts index e7b71fbedd413..1c5593ff71f93 100644 --- a/packages/core/types/src/http/product/store/queries.ts +++ b/packages/core/types/src/http/product/store/queries.ts @@ -6,29 +6,33 @@ import { export interface StoreProductOptionParams extends BaseProductOptionParams {} export interface StoreProductVariantParams extends BaseProductVariantParams {} -export interface StoreProductParams - extends Omit { +export interface StoreProductPricingContext { /** - * Filter by the product's tag(s). + * The ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price. */ - tag_id?: string | string[] + region_id?: string /** - * The ID of the region the products are being viewed from. This is required if you're retrieving product variant prices with taxes. - * - * @privateRemarks - * The region ID and currency_code are not params, but are used for the pricing context. Maybe move to separate type definition. + * The customer's country code. This parameter must be included if you want to apply taxes on the product variant's price. */ - region_id?: string + country_code?: string /** - * The currency code to retrieve prices in. + * The province, which can be taken from a customer's address. This parameter helps further narrowing down the taxes applied on a the product variant's prices. */ - currency_code?: string + province?: string /** - * Filter by the product's variants. + * The ID of the customer's cart, if available. If set, the cart's region and shipping address's country code and province are used instead of the `region_id`, `country_code`, and `province` parameters. */ - variants?: Pick + cart_id?: string +} + +export interface StoreProductListParams + extends Omit, StoreProductPricingContext { /** - * The province the products are being viewed from. This is useful to narrow down the tax context when calculating product variant prices with taxes. + * Filter by the product's tag(s). */ - province?: string + tag_id?: string | string[] + /** + * Filter by the product's variants. + */ + variants?: Pick } diff --git a/packages/medusa/src/api/store/products/[id]/route.ts b/packages/medusa/src/api/store/products/[id]/route.ts index 6c96a075e1b54..76cc55fa789dc 100644 --- a/packages/medusa/src/api/store/products/[id]/route.ts +++ b/packages/medusa/src/api/store/products/[id]/route.ts @@ -6,11 +6,10 @@ import { RequestWithContext, wrapProductsWithTaxPrices, } from "../helpers" -import { StoreGetProductParamsType } from "../validators" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: RequestWithContext, + req: RequestWithContext, res: MedusaResponse ) => { const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) => diff --git a/packages/medusa/src/api/store/products/route.ts b/packages/medusa/src/api/store/products/route.ts index 4fbc50419bf5a..a9741fe8e2fa4 100644 --- a/packages/medusa/src/api/store/products/route.ts +++ b/packages/medusa/src/api/store/products/route.ts @@ -9,7 +9,7 @@ import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers" import { HttpTypes } from "@medusajs/framework/types" export const GET = async ( - req: RequestWithContext, + req: RequestWithContext, res: MedusaResponse ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)