fix(analytics): pre-cargar todos los cupones incluso con 0 interacciones en el sector comercial

This commit is contained in:
2026-03-05 12:13:25 -05:00
parent 4cdd903b8a
commit 51d390c2e1

View File

@ -472,13 +472,15 @@ onMounted(async () => {
{ count: userCount },
{ data: events },
{ data: allBusinesses },
{ data: allShuttles }
{ data: allShuttles },
{ data: allCoupons }
] = await Promise.all([
supabase.from('users').select('*', { count: 'exact', head: true }).eq('is_active', true),
// In a production app with >1M rows we might use a group-by RPC
supabase.from('analytics_events').select('*'),
supabase.from('businesses').select('name'),
supabase.from('shuttles').select('company_name, vehicle_type')
supabase.from('shuttles').select('company_name, vehicle_type'),
supabase.from('coupons').select('title, businesses(name)')
])
const shuttleStats: any = {}
@ -496,6 +498,23 @@ onMounted(async () => {
}
}
// PRE-FILL all coupons so they always show even with 0 clicks
if (allCoupons) {
for (const c of allCoupons) {
// Handle Supabase relation mapping (it might be array or object depending on generated types)
const bizData: any = c.businesses
const bizName = (Array.isArray(bizData) ? bizData[0]?.name : bizData?.name) || 'Desconocido'
if (c.title) {
if (!bizStats[bizName]) {
bizStats[bizName] = { views: 0, promos: 0, favs: 0, social: 0, location: 0, calls: 0, coupons: {} }
}
if (!bizStats[bizName].coupons[c.title]) {
bizStats[bizName].coupons[c.title] = { views: 0, location: 0 }
}
}
}
}
// PRE-FILL all shuttles so they always show even with 0 clicks
if (allShuttles) {
for (const s of allShuttles) {