@@ -71,24 +71,49 @@ export async function GET(
7171 }
7272 }
7373
74- // Get count of approved events for this company
74+ // Get count of approved events and hackathons for this company
7575 const supabase = await createClient ( )
76- const { count : approvedCount } = await supabase
76+ const { count : approvedEventsCount } = await supabase
7777 . from ( 'events' )
7878 . select ( '*' , { count : 'exact' , head : true } )
7979 . eq ( 'company_id' , company . id )
8080 . eq ( 'approval_status' , 'approved' )
8181
82- // Add approved_events_count to company object
83- const companyWithApprovedCount = {
82+ const { count : approvedHackathonsCount } = await supabase
83+ . from ( 'hackathons' )
84+ . select ( '*' , { count : 'exact' , head : true } )
85+ . eq ( 'company_id' , company . id )
86+ . eq ( 'approval_status' , 'approved' )
87+
88+ // Get total participants from events
89+ const { data : events } = await supabase
90+ . from ( 'events' )
91+ . select ( 'registered' )
92+ . eq ( 'company_id' , company . id )
93+ . eq ( 'approval_status' , 'approved' )
94+
95+ // Get total participants from hackathons
96+ const { data : hackathons } = await supabase
97+ . from ( 'hackathons' )
98+ . select ( 'registered' )
99+ . eq ( 'company_id' , company . id )
100+ . eq ( 'approval_status' , 'approved' )
101+
102+ const eventParticipants = events ?. reduce ( ( sum , event ) => sum + ( event . registered || 0 ) , 0 ) || 0
103+ const hackathonParticipants = hackathons ?. reduce ( ( sum , hackathon ) => sum + ( hackathon . registered || 0 ) , 0 ) || 0
104+
105+ // Add calculated fields to company object
106+ const enrichedCompany = {
84107 ...company ,
85- approved_events_count : approvedCount || 0 ,
108+ approved_events_count : approvedEventsCount || 0 ,
109+ approved_hackathons_count : approvedHackathonsCount || 0 ,
110+ total_participants : eventParticipants + hackathonParticipants ,
86111 }
87112
88113 // Cache the result
89- await UnifiedCache . set ( cacheKey , { company : companyWithApprovedCount } , 'API_STANDARD' )
114+ await UnifiedCache . set ( cacheKey , { company : enrichedCompany } , 'API_STANDARD' )
90115
91- return UnifiedCache . createResponse ( { company : companyWithApprovedCount } , 'API_STANDARD' )
116+ return UnifiedCache . createResponse ( { company : enrichedCompany } , 'API_STANDARD' )
92117 } catch ( error ) {
93118 console . error ( 'Error in GET /api/companies/[slug]:' , error )
94119
0 commit comments