Skip to content

Commit

Permalink
fix(medusa,types): fix request query parameter types for store produc…
Browse files Browse the repository at this point in the history
…t routes
  • Loading branch information
shahednasser committed Dec 23, 2024
1 parent c804ae5 commit c626f0e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-chairs-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/medusa": patch
---

fix(medusa,types): fix request query parameter types for store product routes
34 changes: 19 additions & 15 deletions packages/core/types/src/http/product/store/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@ import {

export interface StoreProductOptionParams extends BaseProductOptionParams {}
export interface StoreProductVariantParams extends BaseProductVariantParams {}
export interface StoreProductParams
extends Omit<BaseProductListParams, "tags" | "status" | "categories" | "deleted_at"> {
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<StoreProductVariantParams, "options">
cart_id?: string
}

export interface StoreProductListParams
extends Omit<BaseProductListParams, "tags" | "status" | "categories" | "deleted_at">, 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<StoreProductVariantParams, "options">
}
3 changes: 1 addition & 2 deletions packages/medusa/src/api/store/products/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreGetProductParamsType>,
req: RequestWithContext<HttpTypes.StoreProductPricingContext>,
res: MedusaResponse<HttpTypes.StoreProductResponse>
) => {
const withInventoryQuantity = req.remoteQueryConfig.fields.some((field) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/store/products/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RequestWithContext, wrapProductsWithTaxPrices } from "./helpers"
import { HttpTypes } from "@medusajs/framework/types"

export const GET = async (
req: RequestWithContext<HttpTypes.StoreProductParams>,
req: RequestWithContext<HttpTypes.StoreProductListParams>,
res: MedusaResponse<HttpTypes.StoreProductListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
Expand Down

0 comments on commit c626f0e

Please sign in to comment.