Initial commit v1.1

This commit is contained in:
Rolf
2026-03-18 13:34:41 +01:00
parent cb04bf2ab8
commit b982584244
38 changed files with 3196 additions and 1103 deletions
+30 -23
View File
@@ -1,28 +1,35 @@
import { createClient } from '@/lib/supabase/server'
import { auth } from '@/lib/auth'
import { db } from '@/lib/db'
import { courses, tees } from '@/lib/db/schema'
import { eq } from 'drizzle-orm'
import { headers } from 'next/headers'
import { redirect } from 'next/navigation'
import { NewRoundWizard } from '@/components/round/new-round-wizard'
type Tee = {
id: string
name: string
color: string
course_rating: number
slope_rating: number
}
type Course = {
id: string
name: string
par: number
tees: Tee[]
}
export default async function NewRoundPage() {
const supabase = await createClient()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { data: courses } = await (supabase as any)
.from('courses')
.select('id, name, par, tees(id, name, color, course_rating, slope_rating)')
.order('name')
const session = await auth.api.getSession({ headers: await headers() })
if (!session) redirect('/login')
return <NewRoundWizard courses={(courses as Course[]) ?? []} />
const courseList = await db.select().from(courses).orderBy(courses.name)
const teesData = await db.select().from(tees)
const teesById = teesData.reduce<Record<string, typeof teesData>>((acc, tee) => {
;(acc[tee.courseId] ??= []).push(tee)
return acc
}, {})
const coursesWithTees = courseList.map((c) => ({
id: c.id,
name: c.name,
par: c.par,
tees: (teesById[c.id] ?? []).map((t) => ({
id: t.id,
name: t.name,
color: t.color,
course_rating: parseFloat(t.courseRating),
slope_rating: t.slopeRating,
})),
}))
return <NewRoundWizard courses={coursesWithTees} />
}