All files / web/src/app/api/realtime/profile route.ts

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

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 31 32 33 34                                                                   
/**
 * API route that assembles a child profile for mid-call identification.
 *
 * POST /api/realtime/profile
 * Body: { playerId: string }
 * Returns: { profile: ChildProfile } or { failed: true }
 */

import { NextResponse } from 'next/server'
import { withAuth } from '@/lib/auth/withAuth'
import { assembleChildProfile } from '@/components/toys/number-line/talkToNumber/assembleChildProfile'

export const POST = withAuth(async (request) => {
  try {
    const body = await request.json()
    const { playerId } = body

    if (typeof playerId !== 'string' || !playerId) {
      return NextResponse.json({ error: 'playerId must be a non-empty string' }, { status: 400 })
    }

    const result = await assembleChildProfile(playerId)

    if (result && 'failed' in result) {
      return NextResponse.json({ failed: true })
    }

    return NextResponse.json({ profile: result })
  } catch (error) {
    console.error('[realtime/profile] Error:', error)
    return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
  }
})