54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import { notFound, redirect } from 'next/navigation'
|
|
import LiveSessionClient from './LiveSessionClient'
|
|
|
|
export default async function LiveSessionPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>
|
|
}) {
|
|
const supabase = await createClient()
|
|
const db = supabase as any
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) redirect('/login')
|
|
|
|
const { id } = await params
|
|
|
|
const { data: session } = await db
|
|
.from('sessions')
|
|
.select(`id, short_code, is_active, school_name, class_name, total_participants, created_at, quiz:quizzes(id, title)`)
|
|
.eq('id', id)
|
|
.eq('trainer_id', user.id)
|
|
.single()
|
|
|
|
if (!session) notFound()
|
|
|
|
const { data: participations } = await db
|
|
.from('student_participations')
|
|
.select('id, first_name, last_name, score, status, started_at, completed_at')
|
|
.eq('session_id', id)
|
|
.order('started_at', { ascending: false })
|
|
|
|
const { count: totalQuestions } = await db
|
|
.from('questions')
|
|
.select('id', { count: 'exact', head: true })
|
|
.eq('quiz_id', session.quiz?.id ?? '')
|
|
|
|
return (
|
|
<LiveSessionClient
|
|
session={{
|
|
id: session.id,
|
|
short_code: session.short_code,
|
|
is_active: session.is_active,
|
|
school_name: session.school_name,
|
|
class_name: session.class_name,
|
|
total_participants: session.total_participants,
|
|
quiz_title: session.quiz?.title ?? 'Quiz',
|
|
}}
|
|
initialParticipations={participations ?? []}
|
|
totalQuestions={totalQuestions ?? 0}
|
|
/>
|
|
)
|
|
}
|