fix(dashboard,medusa,types): improve performance for price list prices retrieval (#14138)

## Summary

**What** — What changes are introduced in this PR?

Price lists prices didn't have a dedicated method to query them and instead, relied on being returned as part of price lists. This, however, introduces optimization issues that for price lists with many prices, could cause crashes. The reason being that relations are not paginated and thus, all prices linked to the price list would be returned.

This PR aims to solve this by introducing a dedicated endpoint and avoiding returning the `prices` as part of price lists by default. The idea being that it is up to the user to explicitly express this, which, for small price lists no issues will arise, but for bigger ones, they will easily recognize the performance impact.

**Why** — Why are these changes relevant or necessary?  

Users with large enough price lists would have serious performance issues or even crashes when querying the `/admin/price-lists` endpoints. This is also true when navigating to the price list section of the Admin UI since it queries this same endpoints.

**How** — How have these changes been implemented?

- Removed the `prices` relation to be part of the default fields returned by the `/admin/price-lists/` endpoints. User may still request it by passing it in `fields` query param.
- Added new `/admin/price-lists/[id]/prices` GET endpoint to be able to retrieve a price list prices with pagination.

**Testing** — How have these changes been tested, or how can the reviewer test the feature?

Integration tests.

---

## Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.  
This helps with documentation and ensures maintainers can quickly understand and verify the change.

```ts
// Example usage
```

---

## Checklist

Please ensure the following before requesting a review:

- [x] I have added a **changeset** for this PR
    - Every non-breaking change should be marked as a **patch**
    - To add a changeset, run `yarn changeset` and follow the prompts
- [x] The changes are covered by relevant **tests**
- [x] I have verified the code works as intended locally
- [x] I have linked the related issue(s) if applicable

---

## Additional Context

The current state of the PR fixes the issue on the price list list and detail component. It still doesn't solve the issue for the following screens: Edit Prices & Add Prices

All the prices are still retrieved from the `/admin/price-lists/` endpoint for these. I want first some feedback before changing it to the new endpoint, since the current DataGrid implementation doesn't support pagination and it seems we are passing a default limit for the products to show there, an arbitrarily large number 9999 and there is also a TODO comment of changing that.

This previous point, though, could be implemented in a later PR, so we can already fix the issue in the price list list and detail pages, so at least for large price lists these screens don't explode and smaller price lists can still have its product prices edited, while only large ones will explode when trying to perform this action. @adrien2p @fPolic thoughts?

closes ENTSUP-265, CORE-1239
This commit is contained in:
Nicolas Gorga authored and GitHub committed 2025-12-11 13:13:08 +00:00
1 parent 237b472e73
commit 70929ecac3
17 files changed
+326 -120

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
---
"@medusajs/dashboard": minor
"@medusajs/types": minor
"@medusajs/medusa": minor
---
fix(dashboard,medusa,types): improve performance for price list prices retrieval
@@ -14,6 +14,7 @@ medusaIntegrationTestRunner({
env: {},
testSuite: ({ dbConnection, getContainer, api }) => {
let pricelist1
let pricelist1Prices
let pricelist2
let region1
let product1
@@ -93,6 +94,10 @@ medusaIntegrationTestRunner({
)
).data.price_list
pricelist1Prices = await api
.get(`/admin/price-lists/${pricelist1.id}/prices`, adminHeaders)
.then((res) => res.data.prices)
pricelist2 = (
await api.post(
"/admin/price-lists",
@@ -134,7 +139,7 @@ medusaIntegrationTestRunner({
})
const response = await api.post(
"/admin/price-lists",
"/admin/price-lists?fields=prices.*,prices.price_set.*,prices.price_set.variant.*",
payload,
adminHeaders
)
@@ -189,34 +194,12 @@ medusaIntegrationTestRunner({
status: pricelist1.status,
starts_at: pricelist1.starts_at,
ends_at: pricelist1.ends_at,
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
amount: 100,
currency_code: "usd",
// BREAKING: Min and max quantity are returned as string
min_quantity: 1,
max_quantity: 100,
variant_id: product1.variants[0].id,
created_at: expect.any(String),
updated_at: expect.any(String),
// BREAKING: `variant` and `variants` are not returned as part of the prices
}),
expect.objectContaining({
id: expect.any(String),
amount: 80,
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
variant_id: product1.variants[0].id,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
created_at: expect.any(String),
updated_at: expect.any(String),
})
)
// BREAKING: Prices are not returned as part of the price list if not specified in fields
expect(response.data.price_list).not.toHaveProperty("prices")
})
it("returns a list of price lists", async () => {
@@ -367,22 +350,6 @@ medusaIntegrationTestRunner({
status: "draft",
starts_at: "2022-09-01T00:00:00.000Z",
ends_at: "2022-12-31T00:00:00.000Z",
prices: expect.arrayContaining([
expect.objectContaining({
amount: 100,
currency_code: "usd",
id: expect.any(String),
max_quantity: 100,
min_quantity: 1,
}),
expect.objectContaining({
amount: 80,
currency_code: "usd",
id: expect.any(String),
max_quantity: 500,
min_quantity: 101,
}),
]),
rules: {
"customer.groups.id": [customerGroup1.id],
},
@@ -393,11 +360,12 @@ medusaIntegrationTestRunner({
})
it("updates the amount and currency of a price in the price list", async () => {
const priceToUpdate = pricelist1Prices.find((p) => p.amount === 80)
const payload = {
// BREAKING: Updates of prices happen through the batch endpoint, and doing it through the price list update endpoint is no longer supported
update: [
{
id: pricelist1.prices.find((p) => p.amount === 80).id,
id: priceToUpdate.id,
amount: 250,
currency_code: "eur",
variant_id: product1.variants[0].id,
@@ -411,27 +379,29 @@ medusaIntegrationTestRunner({
adminHeaders
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices).toEqual([
expect.objectContaining({
amount: 100,
currency_code: "usd",
id: expect.any(String),
max_quantity: 100,
min_quantity: 1,
}),
expect.objectContaining({
amount: 250,
currency_code: "eur",
id: expect.any(String),
max_quantity: 500,
min_quantity: 101,
}),
])
expect(response.data.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
amount: 100,
currency_code: "usd",
id: expect.any(String),
max_quantity: 100,
min_quantity: 1,
}),
expect.objectContaining({
amount: 250,
currency_code: "eur",
id: expect.any(String),
max_quantity: 500,
min_quantity: 101,
}),
])
)
})
})
@@ -470,13 +440,13 @@ medusaIntegrationTestRunner({
adminHeaders
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(5)
expect(response.data.price_list.prices).toEqual(
expect(response.data.prices.length).toEqual(5)
expect(response.data.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
@@ -484,7 +454,12 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 1,
max_quantity: 100,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
@@ -492,13 +467,23 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
amount: 45,
currency_code: "usd",
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
min_quantity: 1001,
max_quantity: 2000,
}),
@@ -506,7 +491,12 @@ medusaIntegrationTestRunner({
id: expect.any(String),
amount: 35,
currency_code: "usd",
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
min_quantity: 2001,
max_quantity: 3000,
}),
@@ -514,7 +504,12 @@ medusaIntegrationTestRunner({
id: expect.any(String),
amount: 25,
currency_code: "usd",
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
min_quantity: 3001,
max_quantity: 4000,
}),
@@ -551,13 +546,13 @@ medusaIntegrationTestRunner({
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(2)
expect(response.data.price_list.prices).toEqual(
expect(response.data.prices.length).toEqual(2)
expect(response.data.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
@@ -565,7 +560,12 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 1,
max_quantity: 100,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
@@ -573,7 +573,12 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
])
)
@@ -605,13 +610,13 @@ medusaIntegrationTestRunner({
adminHeaders
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(4)
expect(response.data.price_list.prices).toEqual(
expect(response.data.prices.length).toEqual(4)
expect(response.data.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
@@ -619,7 +624,12 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 1,
max_quantity: 100,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
@@ -627,20 +637,40 @@ medusaIntegrationTestRunner({
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
amount: 100,
currency_code: "eur",
rules: { region_id: region1.id },
variant_id: product1.variants[0].id,
price_rules: expect.arrayContaining([
expect.objectContaining({
attribute: "region_id",
value: region1.id,
}),
]),
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
expect.objectContaining({
id: expect.any(String),
amount: 200,
currency_code: "eur",
variant_id: product1.variants[0].id,
price_set: expect.objectContaining({
id: expect.any(String),
variant: {
id: product1.variants[0].id,
},
}),
}),
])
)
@@ -680,41 +710,48 @@ medusaIntegrationTestRunner({
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(0)
expect(response.data.prices.length).toEqual(0)
})
})
describe("DELETE /admin/price-lists/:id/prices/batch", () => {
// BREAKING: The batch method signature changed
it("Deletes several prices associated with a price list", async () => {
const priceToDelete = pricelist1Prices.find((p) => p.amount === 100)
await api.post(
`/admin/price-lists/${pricelist1.id}/prices/batch`,
{
delete: [pricelist1.prices[0].id],
delete: [priceToDelete.id],
},
adminHeaders
)
const response = await api.get(
`/admin/price-lists/${pricelist1.id}`,
`/admin/price-lists/${pricelist1.id}/prices`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.price_list.prices).toEqual([
expect.objectContaining({
amount: 80,
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
variant_id: product1.variants[0].id,
}),
])
expect(response.data.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
amount: 80,
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
price_set: expect.objectContaining({
variant: expect.objectContaining({
id: product1.variants[0].id,
}),
}),
}),
])
)
})
})
@@ -99,7 +99,10 @@ medusaIntegrationTestRunner({
},
])
let response = await api.get(`/admin/price-lists`, adminHeaders)
let response = await api.get(
`/admin/price-lists?fields=prices.*,prices.price_rules.*,prices.price_set.*,prices.price_set.variant.*`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
@@ -130,9 +133,16 @@ medusaIntegrationTestRunner({
updated_at: expect.any(String),
deleted_at: null,
price_set_id: expect.any(String),
price_list_id: expect.any(String),
title: null,
rules: {
region_id: region.id,
},
rules_count: 1,
raw_amount: expect.objectContaining({
value: "5000",
precision: 20,
}),
},
],
},
@@ -258,7 +268,7 @@ medusaIntegrationTestRunner({
])
let response = await api.get(
`/admin/price-lists/${priceList.id}`,
`/admin/price-lists/${priceList.id}?fields=prices.*,prices.price_rules.*,prices.price_set.*,prices.price_set.variant.*`,
adminHeaders
)
@@ -288,8 +298,15 @@ medusaIntegrationTestRunner({
variant_id: variant.id,
created_at: expect.any(String),
updated_at: expect.any(String),
price_list_id: expect.any(String),
price_set_id: expect.any(String),
deleted_at: null,
rules_count: 1,
raw_amount: expect.objectContaining({
value: "5000",
precision: 20,
}),
title: null,
rules: {
region_id: region.id,
},
@@ -355,7 +372,7 @@ medusaIntegrationTestRunner({
}
const response = await api.post(
`admin/price-lists`,
`admin/price-lists?fields=prices.*,prices.price_rules.*,prices.price_set.*,prices.price_set.variant.*`,
data,
adminHeaders
)
@@ -388,6 +405,12 @@ medusaIntegrationTestRunner({
updated_at: expect.any(String),
deleted_at: null,
price_set_id: expect.any(String),
rules_count: 1,
raw_amount: expect.objectContaining({
value: "400",
precision: 20,
}),
title: null,
rules: {
region_id: region.id,
},
@@ -14,7 +14,12 @@ import { customerGroupsQueryKeys } from "./customer-groups"
import { productsQueryKeys } from "./products"
const PRICE_LISTS_QUERY_KEY = "price-lists" as const
const PRICE_LIST_PRICES_QUERY_KEY = "price-list-prices" as const
export const priceListsQueryKeys = queryKeysFactory(PRICE_LISTS_QUERY_KEY)
export const priceListPricesQueryKeys = queryKeysFactory(
PRICE_LIST_PRICES_QUERY_KEY
)
export const usePriceList = (
id: string,
@@ -31,7 +36,7 @@ export const usePriceList = (
) => {
const { data, ...rest } = useQuery({
queryFn: () => sdk.admin.priceList.retrieve(id, query),
queryKey: priceListsQueryKeys.detail(id),
queryKey: priceListsQueryKeys.detail(id, query),
...options,
})
@@ -124,6 +129,25 @@ export const useDeletePriceList = (
})
}
export const usePriceListPrices = (
id: string,
query?: HttpTypes.AdminPriceListPriceListParams,
options?: UseQueryOptions<
HttpTypes.AdminPriceListPriceListResponse,
FetchError,
HttpTypes.AdminPriceListPriceListResponse,
QueryKey
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => sdk.admin.priceList.prices(id, query),
queryKey: priceListPricesQueryKeys.detail(id, query),
...options,
})
return { ...data, ...rest }
}
export const useBatchPriceListPrices = (
id: string,
query?: HttpTypes.AdminPriceListParams,
@@ -141,6 +165,9 @@ export const useBatchPriceListPrices = (
queryKey: priceListsQueryKeys.detail(id),
})
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
queryClient.invalidateQueries({
queryKey: priceListPricesQueryKeys.detail(id),
})
options?.onSuccess?.(data, variables, context)
},
@@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next"
import { ActionMenu } from "../../../../../components/common/action-menu"
import { useDeletePriceListAction } from "../../../common/hooks/use-delete-price-list-action"
import { getPriceListStatus } from "../../../common/utils"
import { usePriceListPrices } from "../../../../../hooks/api"
type PriceListGeneralSectionProps = {
priceList: HttpTypes.AdminPriceList
@@ -15,8 +16,13 @@ export const PriceListGeneralSection = ({
priceList,
}: PriceListGeneralSectionProps) => {
const { t } = useTranslation()
const overrideCount = priceList.prices?.length || 0
const {
count: overrideCount,
isLoading,
error,
} = usePriceListPrices(priceList.id, {
limit: 1,
})
const { color, text } = getPriceListStatus(t, priceList)
@@ -77,9 +83,11 @@ export const PriceListGeneralSection = ({
<Text leading="compact" size="small" weight="plus">
{t("priceLists.fields.priceOverrides.label")}
</Text>
<Text size="small" className="text-pretty">
{overrideCount || "-"}
</Text>
{!isLoading && !error && (
<Text size="small" className="text-pretty">
{overrideCount || "-"}
</Text>
)}
</div>
</Container>
)
@@ -0,0 +1,19 @@
import { usePriceListPrices } from "../../../../../hooks/api/price-lists"
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
import { TextCell } from "../../../../../components/table/table-cells/common/text-cell"
type PriceCountCellProps = {
priceListId: string
}
export const PriceCountCell = ({ priceListId }: PriceCountCellProps) => {
const { count, isLoading } = usePriceListPrices(priceListId, {
limit: 1,
})
if (isLoading) {
return <PlaceholderCell />
}
return <TextCell text={count && count > 0 ? count.toString() : "-"} />
}
@@ -4,12 +4,10 @@ import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import { StatusCell } from "../../../../../components/table/table-cells/common/status-cell"
import {
TextCell,
TextHeader,
} from "../../../../../components/table/table-cells/common/text-cell"
import { TextHeader } from "../../../../../components/table/table-cells/common/text-cell"
import { getPriceListStatus } from "../../../common/utils"
import { PriceListListTableActions } from "./price-list-list-table-actions"
import { PriceCountCell } from "./price-count-cell"
const columnHelper = createColumnHelper<HttpTypes.AdminPriceList>()
@@ -30,9 +28,10 @@ export const usePricingTableColumns = () => {
return <StatusCell color={color}>{text}</StatusCell>
},
}),
columnHelper.accessor("prices", {
columnHelper.display({
id: "price_overrides",
header: t("priceLists.fields.priceOverrides.header"),
cell: (info) => <TextCell text={`${info.getValue()?.length || "-"}`} />,
cell: ({ row }) => <PriceCountCell priceListId={row.original.id} />,
}),
columnHelper.display({
id: "actions",
@@ -7,7 +7,10 @@ import { PriceListPricesAddForm } from "./components/price-list-prices-add-form"
export const PriceListProductsAdd = () => {
const { id } = useParams<{ id: string }>()
const { price_list, isPending, isError, error } = usePriceList(id!)
const { price_list, isPending, isError, error } = usePriceList(id!, {
fields:
"*prices,prices.price_set.variant.id,prices.price_rules.attribute,prices.price_rules.value",
})
const { currencies, regions, pricePreferences, isReady } =
usePriceListCurrencyData()
@@ -10,7 +10,9 @@ export const PriceListPricesEdit = () => {
const [searchParams] = useSearchParams()
const ids = searchParams.get("ids[]")
const { price_list, isLoading, isError, error } = usePriceList(id!)
const { price_list, isLoading, isError, error } = usePriceList(id!, {
fields: "*prices,prices.price_set.variant.id,prices.price_rules.attribute,prices.price_rules.value",
})
const productIds = ids?.split(",")
const {
@@ -279,6 +279,36 @@ export class PriceList {
)
}
/**
* This method retrieves the prices of a price list. It sends a request to the
* [Get Prices](https://docs.medusajs.com/v2/api/admin#price-lists_getpricelistsidprices)
* API route.
*
* @param id - The price list's ID.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's prices.
*
* @example
* sdk.admin.priceList.prices("plist_123")
* .then(({ prices }) => {
* console.log(prices)
* })
*/
async prices(
id: string,
query?: HttpTypes.AdminPriceListPriceListParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminPriceListPriceListResponse>(
`/admin/price-lists/${id}/prices`,
{
method: "GET",
headers,
query,
}
)
}
/**
* This method removes products from a price list. It sends a request to the
* [Remove Product](https://docs.medusajs.com/v2/api/admin#price-lists_postpricelistsidproducts)
@@ -32,3 +32,7 @@ export interface AdminPriceListListParams
}
export interface AdminPriceListParams extends SelectParams {}
export interface AdminPriceListPriceListParams
extends FindParams,
BaseFilterable<AdminPriceListPriceListParams> {}
@@ -38,3 +38,8 @@ export interface AdminPriceListBatchResponse {
deleted: boolean
}
}
export interface AdminPriceListPriceListResponse
extends PaginatedResponse<{
prices: AdminPrice[]
}> {}
@@ -4,7 +4,7 @@ import {
MedusaResponse,
} from "@medusajs/framework/http"
import { listPrices } from "../../../queries"
import { adminPriceListPriceRemoteQueryFields } from "../../../query-config"
import { adminPriceListPriceQueryFields } from "../../../query-config"
import { BatchMethodRequest, HttpTypes } from "@medusajs/framework/types"
import {
AdminCreatePriceListPriceType,
@@ -44,12 +44,12 @@ export const POST = async (
listPrices(
result.created.map((c) => c.id),
req.scope,
adminPriceListPriceRemoteQueryFields
adminPriceListPriceQueryFields
),
listPrices(
result.updated.map((c) => c.id),
req.scope,
adminPriceListPriceRemoteQueryFields
adminPriceListPriceQueryFields
),
])
@@ -0,0 +1,26 @@
import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"
import { HttpTypes } from "@medusajs/types"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
export const GET = async (
req: AuthenticatedMedusaRequest<HttpTypes.AdminPriceListParams>,
res: MedusaResponse<HttpTypes.AdminPriceListPriceListResponse>
) => {
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
const result = await query.graph({
entity: "price",
fields: req.queryConfig.fields,
filters: {
...req.filterableFields,
price_list_id: req.params.id,
},
pagination: req.queryConfig.pagination,
})
res.status(200).json({
prices: result.data,
count: result.metadata?.count ?? 0,
offset: result.metadata?.skip ?? 0,
limit: result.metadata?.take ?? 0,
})
}
@@ -10,6 +10,7 @@ import {
AdminCreatePriceList,
AdminCreatePriceListPrice,
AdminGetPriceListParams,
AdminGetPriceListPriceParams,
AdminGetPriceListPricesParams,
AdminGetPriceListsParams,
AdminRemoveProductsPriceList,
@@ -44,7 +45,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
middlewares: [
validateAndTransformBody(AdminCreatePriceList),
validateAndTransformQuery(
AdminGetPriceListPricesParams,
AdminGetPriceListsParams,
QueryConfig.retrivePriceListQueryConfig
),
],
@@ -55,7 +56,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
middlewares: [
validateAndTransformBody(AdminUpdatePriceList),
validateAndTransformQuery(
AdminGetPriceListPricesParams,
AdminGetPriceListParams,
QueryConfig.retrivePriceListQueryConfig
),
],
@@ -71,6 +72,16 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["GET"],
matcher: "/admin/price-lists/:id/prices",
middlewares: [
validateAndTransformQuery(
AdminGetPriceListPricesParams,
QueryConfig.listPriceListPriceQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/price-lists/:id/prices/batch",
@@ -82,7 +93,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
createBatchBody(AdminCreatePriceListPrice, AdminUpdatePriceListPrice)
),
validateAndTransformQuery(
AdminGetPriceListPricesParams,
AdminGetPriceListPriceParams,
QueryConfig.listPriceListPriceQueryConfig
),
],
@@ -2,7 +2,8 @@ export enum PriceListRelations {
PRICES = "prices",
}
export const adminPriceListPriceRemoteQueryFields = [
// Note: renamed to avoid referencing remoteQuery which is legacy
export const adminPriceListPriceQueryFields = [
"id",
"currency_code",
"amount",
@@ -29,11 +30,10 @@ export const adminPriceListRemoteQueryFields = [
"deleted_at",
"price_list_rules.value",
"price_list_rules.attribute",
...adminPriceListPriceRemoteQueryFields.map((field) => `prices.${field}`),
]
export const retrivePriceListPriceQueryConfig = {
defaults: adminPriceListPriceRemoteQueryFields,
defaults: adminPriceListPriceQueryFields,
isList: false,
}
@@ -7,7 +7,12 @@ import {
} from "../../utils/validators"
import { applyAndAndOrOperators } from "../../utils/common-validators"
export const AdminGetPriceListPricesParams = createSelectParams()
export const AdminGetPriceListPriceParams = createSelectParams()
export const AdminGetPriceListPricesParams = createFindParams({
offset: 0,
limit: 50,
})
export const AdminGetPriceListsParamsFields = z.object({
q: z.string().optional(),