fix: address code review issues — nutriscore field name, cache write isolation, missing rate limiter, dead props
This commit is contained in:
@@ -69,8 +69,12 @@ export async function searchBabyProducts(query) {
|
||||
.map(transformOFFProduct)
|
||||
.filter(Boolean);
|
||||
|
||||
try {
|
||||
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(products));
|
||||
console.log(`Cached ${products.length} OFF products for: ${searchTerm}`);
|
||||
} catch (cacheErr) {
|
||||
// cache write failed, still return the data
|
||||
}
|
||||
return products;
|
||||
}
|
||||
|
||||
@@ -104,8 +108,12 @@ export async function getBabyProductDetails(barcode) {
|
||||
const product = transformOFFProduct(response.data.product);
|
||||
|
||||
if (product) {
|
||||
try {
|
||||
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(product));
|
||||
console.log(`Cached OFF product: ${barcode}`);
|
||||
} catch (cacheErr) {
|
||||
// cache write failed, still return the data
|
||||
}
|
||||
return product;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ app.get('/api/medicines/:medicineId', async (req, res) => {
|
||||
|
||||
// ========== UNIFIED PRODUCT SEARCH ==========
|
||||
|
||||
app.get('/api/products/search', async (req, res) => {
|
||||
app.get('/api/products/search', searchLimiter, async (req, res) => {
|
||||
try {
|
||||
const { q } = req.query;
|
||||
if (!q || q.trim().length < 2) {
|
||||
|
||||
@@ -6,9 +6,8 @@ import {
|
||||
subscribeToPush,
|
||||
unsubscribeFromPush,
|
||||
} from '../utils/notifications.js';
|
||||
import ProductResults from './ProductResults';
|
||||
|
||||
function MedicineResults({ medicines, products = [], onSelect, onSelectProduct, query, currentUser, onLoginRequest }) {
|
||||
function MedicineResults({ medicines, onSelect, query, currentUser, onLoginRequest }) {
|
||||
if (medicines.length === 0 && query.length >= 2) {
|
||||
return (
|
||||
<div className="no-results">
|
||||
@@ -28,12 +27,6 @@ function MedicineResults({ medicines, products = [], onSelect, onSelectProduct,
|
||||
onLoginRequest={onLoginRequest}
|
||||
/>
|
||||
))}
|
||||
{products.length > 0 && (
|
||||
<div className="mt-6">
|
||||
<h3 className="text-lg font-semibold mb-3">Parafarmacia y Bebé</h3>
|
||||
<ProductResults products={products} onSelect={onSelectProduct} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ function ProductResults({ products, onSelect }) {
|
||||
}
|
||||
|
||||
function ProductCard({ product, onSelect }) {
|
||||
const nutriScore = product.nutri_score;
|
||||
const nutriScore = product.nutriscore;
|
||||
const nutriScoreColors = {
|
||||
a: '#16a34a',
|
||||
b: '#65a30d',
|
||||
|
||||
Reference in New Issue
Block a user