Skip to content

Commit eebf9ef

Browse files
authored
Merge pull request #351 from codeunia-dev/fix/hackathon
Fix/hackathon: Update hackathon schema and add company-level participant metrics
2 parents ab5cea5 + 1a7b0d5 commit eebf9ef

File tree

6 files changed

+98
-36
lines changed

6 files changed

+98
-36
lines changed

app/api/companies/[slug]/route.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/companies/[slug]/hackathons/page.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ interface Hackathon {
3131
description: string
3232
excerpt: string
3333
image?: string
34-
start_date: string
35-
end_date: string
36-
location: string
37-
mode: string
34+
date: string
35+
registration_deadline?: string
36+
location?: string
37+
mode?: string
3838
prize_pool?: string
39-
max_team_size: number
40-
min_team_size: number
41-
registered_teams: number
42-
max_teams: number
39+
max_team_size?: number
40+
min_team_size?: number
41+
registered?: number
42+
capacity?: number
4343
status: string
4444
tags: string[]
45-
organizer: string
45+
organizer?: string
46+
total_registrations?: number
47+
duration?: string
4648
}
4749

4850
export default function CompanyHackathonsPage() {
@@ -336,27 +338,30 @@ export default function CompanyHackathonsPage() {
336338
<div className="grid grid-cols-2 gap-2 text-xs mb-2">
337339
<div className="flex items-center gap-1">
338340
<Calendar className="h-3 w-3" />
339-
{new Date(hackathon.start_date).toLocaleDateString("en-US", {
340-
month: "short",
341-
day: "numeric",
342-
})}
341+
{hackathon.date && !isNaN(new Date(hackathon.date).getTime())
342+
? new Date(hackathon.date).toLocaleDateString("en-US", {
343+
month: "short",
344+
day: "numeric",
345+
year: "numeric",
346+
})
347+
: "TBA"}
343348
</div>
344349
<div className="flex items-center gap-1">
345350
<Clock className="h-3 w-3" />
346-
{Math.ceil(
347-
(new Date(hackathon.end_date).getTime() -
348-
new Date(hackathon.start_date).getTime()) /
349-
(1000 * 60 * 60 * 24)
350-
)}{" "}
351-
days
351+
{hackathon.registration_deadline && !isNaN(new Date(hackathon.registration_deadline).getTime())
352+
? `Reg: ${new Date(hackathon.registration_deadline).toLocaleDateString("en-US", {
353+
month: "short",
354+
day: "numeric",
355+
})}`
356+
: hackathon.duration || "TBA"}
352357
</div>
353358
<div className="flex items-center gap-1">
354359
<MapPin className="h-3 w-3" />
355-
{hackathon.mode}
360+
{hackathon.location || hackathon.mode || "TBA"}
356361
</div>
357362
<div className="flex items-center gap-1">
358363
<Users className="h-3 w-3" />
359-
{hackathon.registered_teams}/{hackathon.max_teams} teams
364+
{hackathon.registered || 0} registered
360365
</div>
361366
</div>
362367

components/companies/CompanyCard.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ export function CompanyCard({
7979
{showStats && (
8080
<CardFooter className="border-t pt-4">
8181
<div className="flex items-center justify-between w-full text-xs text-muted-foreground">
82-
<div className="flex items-center gap-1">
83-
<Calendar className="h-3.5 w-3.5" />
84-
<span>{company.approved_events_count ?? company.total_events ?? 0} events</span>
82+
<div className="flex items-center gap-4">
83+
<div className="flex items-center gap-1">
84+
<Calendar className="h-3.5 w-3.5" />
85+
<span>{company.approved_events_count ?? company.total_events ?? 0} events</span>
86+
</div>
87+
<div className="flex items-center gap-1">
88+
<Calendar className="h-3.5 w-3.5" />
89+
<span>{company.approved_hackathons_count ?? company.total_hackathons ?? 0} hackathons</span>
90+
</div>
8591
</div>
8692
<div className="flex items-center gap-1">
8793
<Users className="h-3.5 w-3.5" />
88-
<span>{company.total_participants} participants</span>
94+
<span>{company.total_participants ?? 0} participants</span>
8995
</div>
9096
</div>
9197
</CardFooter>

components/companies/CompanyProfile.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
126126
</div>
127127
<div className="space-y-1">
128128
<p className="text-2xl font-bold text-primary">
129-
{company.total_hackathons || 0}
129+
{company.approved_hackathons_count ?? company.total_hackathons ?? 0}
130130
</p>
131131
<p className="text-xs text-muted-foreground">Hackathons</p>
132132
</div>
133133
<div className="space-y-1">
134134
<p className="text-2xl font-bold text-primary">
135-
{company.total_registrations || 0}
135+
{company.total_participants ?? 0}
136136
</p>
137-
<p className="text-xs text-muted-foreground">Registrations</p>
137+
<p className="text-xs text-muted-foreground">Participants</p>
138138
</div>
139139
</div>
140140
</CardContent>

lib/services/company-service.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class CompanyService {
371371
)
372372
}
373373

374-
// For each company, get the count of approved events
374+
// For each company, get the count of approved events, hackathons, and total participants
375375
const companiesWithApprovedCount = await Promise.all(
376376
(companies || []).map(async (company) => {
377377
const { count: approvedCount } = await supabase
@@ -380,9 +380,34 @@ class CompanyService {
380380
.eq('company_id', company.id)
381381
.eq('approval_status', 'approved')
382382

383+
const { count: hackathonsCount } = await supabase
384+
.from('hackathons')
385+
.select('*', { count: 'exact', head: true })
386+
.eq('company_id', company.id)
387+
.eq('approval_status', 'approved')
388+
389+
// Get total participants from events
390+
const { data: events } = await supabase
391+
.from('events')
392+
.select('registered')
393+
.eq('company_id', company.id)
394+
.eq('approval_status', 'approved')
395+
396+
// Get total participants from hackathons
397+
const { data: hackathons } = await supabase
398+
.from('hackathons')
399+
.select('registered')
400+
.eq('company_id', company.id)
401+
.eq('approval_status', 'approved')
402+
403+
const eventParticipants = events?.reduce((sum, event) => sum + (event.registered || 0), 0) || 0
404+
const hackathonParticipants = hackathons?.reduce((sum, hackathon) => sum + (hackathon.registered || 0), 0) || 0
405+
383406
return {
384407
...company,
385408
approved_events_count: approvedCount || 0,
409+
approved_hackathons_count: hackathonsCount || 0,
410+
total_participants: eventParticipants + hackathonParticipants,
386411
}
387412
})
388413
)

types/company.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface Company {
4444
total_participants: number
4545
total_registrations: number
4646
approved_events_count?: number // Count of approved events only (for public display)
47+
approved_hackathons_count?: number // Count of approved hackathons only (for public display)
4748
}
4849

4950
export interface CompanyAddress {

0 commit comments

Comments
 (0)