fix: handle both array and object responses in admin search

The CIMA search API returns {results: [...]} but the admin panel
was treating it as an array, causing CIMA products to be lost.

Now handles both formats:
- Array: [...]
- Object: {results: [...]}
This commit is contained in:
Antoni Nuñez Romeu
2026-07-16 16:32:24 +02:00
parent dca7e373cd
commit 26e7d92079
2 changed files with 30 additions and 3 deletions
@@ -72,12 +72,16 @@ function PharmacyProductLink() {
})
]);
const cimaData = cimaRes.status === 'fulfilled' ? await cimaRes.value.json() : [];
const cimaData = cimaRes.status === 'fulfilled' ? await cimaRes.value.json() : { results: [] };
const paraData = paraRes.status === 'fulfilled' ? await paraRes.value.json() : { results: [] };
// Handle both array and object responses
const cimaResults = Array.isArray(cimaData) ? cimaData : (cimaData.results || []);
const paraResults = Array.isArray(paraData) ? paraData : (paraData.results || []);
const allResults = [
...(Array.isArray(cimaData) ? cimaData : []),
...(paraData.results || []).map(p => ({ ...p, source: p.source || 'parapharmacy' }))
...cimaResults,
...paraResults.map(p => ({ ...p, source: p.source || 'parapharmacy' }))
];
setProductResults(allResults);