From 51d390c2e187db0274a7ab3698b45d897b14a53b Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Thu, 5 Mar 2026 12:13:25 -0500 Subject: [PATCH] fix(analytics): pre-cargar todos los cupones incluso con 0 interacciones en el sector comercial --- frontend/src/views/StrategicAnalytics.vue | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/StrategicAnalytics.vue b/frontend/src/views/StrategicAnalytics.vue index 94aff6e..99ba5ea 100644 --- a/frontend/src/views/StrategicAnalytics.vue +++ b/frontend/src/views/StrategicAnalytics.vue @@ -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) {