All files / web/src/app/api/number-line/shared-history route.ts

0% Statements 0/29
0% Branches 0/1
0% Functions 0/1
0% Lines 0/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                                           
import { NextResponse, type NextRequest } from 'next/server'
import { withAuth } from '@/lib/auth/withAuth'
import { getUserId } from '@/lib/viewer'
import { getSharedHistory } from '@/lib/number-line/shared-history'

/** GET /api/number-line/shared-history?playerId=X&callerNumber=Y */
export const GET = withAuth(async (request: NextRequest) => {
  try {
    const userId = await getUserId()
    const url = new URL(request.url)
    const playerId = url.searchParams.get('playerId')
    const callerNumberStr = url.searchParams.get('callerNumber')

    if (!playerId || !callerNumberStr) {
      return NextResponse.json({ error: 'Missing playerId or callerNumber' }, { status: 400 })
    }

    const callerNumber = Number(callerNumberStr)
    if (!Number.isFinite(callerNumber)) {
      return NextResponse.json({ error: 'Invalid callerNumber' }, { status: 400 })
    }

    const history = await getSharedHistory(playerId, callerNumber, userId)
    return NextResponse.json({ history })
  } catch (err) {
    console.error('[number-line/shared-history] GET failed:', err)
    return NextResponse.json({ error: 'Failed to load shared history' }, { status: 500 })
  }
})