diff --git a/web/src/components/ShopCard.tsx b/web/src/components/ShopCard.tsx
index c8667d0..6d83670 100644
--- a/web/src/components/ShopCard.tsx
+++ b/web/src/components/ShopCard.tsx
@@ -21,13 +21,13 @@ export const ShopCard = ({ shop }: { shop: BarberShop }) => (
- {shop.rating.toFixed(1)}
+ {(shop.rating || 0).toFixed(1)}
- {shop.services.length} serviços
+ {(shop.services || []).length} serviços
•
- {shop.barbers.length} barbeiros
+ {(shop.barbers || []).length} barbeiros
diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx
index 1da73a6..56e2261 100644
--- a/web/src/pages/Explore.tsx
+++ b/web/src/pages/Explore.tsx
@@ -33,30 +33,30 @@ export default function Explore() {
// Regra 2: Restrições de Chip
const passesFilter = (shop: (typeof shops)[number]) => {
- if (filter === 'top') return shop.rating >= 4.7;
- if (filter === 'produtos') return shop.products.length > 0;
- if (filter === 'barbeiros') return shop.barbers.length >= 2;
- if (filter === 'servicos') return shop.services.length >= 2;
+ if (filter === 'top') return (shop.rating || 0) >= 4.7;
+ if (filter === 'produtos') return (shop.products || []).length > 0;
+ if (filter === 'barbeiros') return (shop.barbers || []).length >= 2;
+ if (filter === 'servicos') return (shop.services || []).length >= 2;
return true;
};
// Aplicação condicional com Sort
const sorted = [...shops]
- .filter((shop) => matchesQuery(shop.name, shop.address))
+ .filter((shop) => matchesQuery(shop.name, shop.address || ''))
.filter(passesFilter)
.sort((a, b) => {
- if (sortBy === 'avaliacao') return b.rating - a.rating;
- if (sortBy === 'servicos') return b.services.length - a.services.length;
+ if (sortBy === 'avaliacao') return (b.rating || 0) - (a.rating || 0);
+ if (sortBy === 'servicos') return (b.services || []).length - (a.services || []).length;
if (sortBy === 'preco') {
// Extrai o preço mínimo nos serviços oferecidos e compara
- const aMin = Math.min(...a.services.map((s) => s.price));
- const bMin = Math.min(...b.services.map((s) => s.price));
+ const aMin = (a.services || []).length ? Math.min(...a.services.map((s) => s.price)) : Infinity;
+ const bMin = (b.services || []).length ? Math.min(...b.services.map((s) => s.price)) : Infinity;
return aMin - bMin;
}
// Critério por defeito ou quebra de empate: Avaliação descendente
- if (b.rating !== a.rating) return b.rating - a.rating;
- return b.services.length - a.services.length;
+ if (b.rating !== a.rating) return (b.rating || 0) - (a.rating || 0);
+ return (b.services || []).length - (a.services || []).length;
});
return sorted;