feat(MED-100): analysis package products by product type

This commit is contained in:
2025-07-24 08:04:04 +03:00
parent e59ad6af00
commit 23f656ccc9
2 changed files with 10 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import { cache } from 'react'; import { cache } from 'react';
import { listCollections, listProducts, listRegions } from "@lib/data"; import { listProductTypes, listProducts, listRegions } from "@lib/data";
async function countryCodesLoader() { async function countryCodesLoader() {
const countryCodes = await listRegions().then((regions) => const countryCodes = await listRegions().then((regions) =>
@@ -10,26 +10,24 @@ async function countryCodesLoader() {
} }
export const loadCountryCodes = cache(countryCodesLoader); export const loadCountryCodes = cache(countryCodesLoader);
async function collectionsLoader() { async function productTypesLoader() {
const { collections } = await listCollections({ const { productTypes } = await listProductTypes();
fields: 'id, handle', return productTypes ?? [];
});
return collections ?? [];
} }
export const loadCollections = cache(collectionsLoader); export const loadProductTypes = cache(productTypesLoader);
async function analysisPackagesLoader() { async function analysisPackagesLoader() {
const [countryCodes, collections] = await Promise.all([loadCountryCodes(), loadCollections()]); const [countryCodes, productTypes] = await Promise.all([loadCountryCodes(), loadProductTypes()]);
const countryCode = countryCodes[0]!; const countryCode = countryCodes[0]!;
const collection = collections.find(({ handle }) => handle === 'analysis-packages'); const productType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
if (!collection) { if (!productType) {
return { analysisPackages: [], countryCode }; return { analysisPackages: [], countryCode };
} }
const { response } = await listProducts({ const { response } = await listProducts({
countryCode, countryCode,
queryParams: { limit: 100, collection_id: collection?.id }, queryParams: { limit: 100, "type_id[0]": productType.id },
}); });
return { analysisPackages: response.products, countryCode }; return { analysisPackages: response.products, countryCode };
} }

View File

@@ -14,7 +14,7 @@ export const listProducts = async ({
regionId, regionId,
}: { }: {
pageParam?: number pageParam?: number
queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams & { collection_id?: string } queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams & { "type_id[0]"?: string }
countryCode?: string countryCode?: string
regionId?: string regionId?: string
}): Promise<{ }): Promise<{