appcontext

This commit is contained in:
2026-03-10 17:07:16 +00:00
parent dd32b09127
commit 1ad78609e2
2 changed files with 21 additions and 3 deletions

View File

@@ -104,12 +104,22 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
return;
}
// Associar serviços e barbeiros às respetivas shops, simulando um INNER JOIN nativo do SQL
// Query 4: Obtém a listagem global de Produtos (tabela 'products')
const { data: productsData, error: productsError } = await supabase
.from('products')
.select('*');
if (productsError) {
console.error("Erro ao buscar products:", productsError);
return;
}
// Associar serviços, barbeiros e produtos às respetivas shops, simulando um INNER JOIN nativo do SQL
const shopsWithServices = shopsData.map((shop) => ({
...shop,
// Relaciona a 'foreign key' (shop_id) com o resgistro primário (shop.id)
services: servicesData.filter((s) => s.shop_id === shop.id),
products: [],
products: productsData.filter((p) => p.shop_id === shop.id),
barbers: barbersData.filter((b) => b.shop_id === shop.id),
}));