Files
biblical-guide.com/app/api/bible/versions/route.ts
Andrei 920798966a Fix bible reader version filtering and improve UI
- Fix API to show all 1416+ bible versions with language filtering toggle
- Add default language-specific filtering with option to show all versions
- Fix books API to work with cross-language version selection
- Add toggle button with visual feedback and version count display
- Improve dropdown scrolling and add language indicators
- Maintain backward compatibility while fixing core functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:27:21 +00:00

39 lines
1.1 KiB
TypeScript

import { NextResponse } from 'next/server'
import { prisma } from '@/lib/db'
export const runtime = 'nodejs'
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const locale = (searchParams.get('locale') || searchParams.get('language') || 'ro').toLowerCase()
const showAll = searchParams.get('all') === 'true'
let whereClause = {}
if (!showAll) {
const langCandidates = Array.from(new Set([locale, locale.toLowerCase(), locale.toUpperCase()]))
whereClause = { language: { in: langCandidates } }
}
const versions = await prisma.bibleVersion.findMany({
where: whereClause,
orderBy: [{ isDefault: 'desc' }, { language: 'asc' }, { name: 'asc' }]
})
return NextResponse.json({
success: true,
versions: versions.map(v => ({
id: v.id,
name: v.name,
abbreviation: v.abbreviation,
language: v.language,
isDefault: v.isDefault,
}))
})
} catch (error) {
console.error('Error fetching versions:', error)
return NextResponse.json({ success: false, versions: [] }, { status: 500 })
}
}