fix(analytics): pre-cargar todos los cupones incluso con 0 interacciones en el sector comercial
This commit is contained in:
@ -472,13 +472,15 @@ onMounted(async () => {
|
|||||||
{ count: userCount },
|
{ count: userCount },
|
||||||
{ data: events },
|
{ data: events },
|
||||||
{ data: allBusinesses },
|
{ data: allBusinesses },
|
||||||
{ data: allShuttles }
|
{ data: allShuttles },
|
||||||
|
{ data: allCoupons }
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
supabase.from('users').select('*', { count: 'exact', head: true }).eq('is_active', true),
|
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
|
// In a production app with >1M rows we might use a group-by RPC
|
||||||
supabase.from('analytics_events').select('*'),
|
supabase.from('analytics_events').select('*'),
|
||||||
supabase.from('businesses').select('name'),
|
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 = {}
|
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
|
// PRE-FILL all shuttles so they always show even with 0 clicks
|
||||||
if (allShuttles) {
|
if (allShuttles) {
|
||||||
for (const s of allShuttles) {
|
for (const s of allShuttles) {
|
||||||
|
|||||||
Reference in New Issue
Block a user