diff --git a/api/admin/index.js b/api/admin/index.js index bf80fff..f238816 100644 --- a/api/admin/index.js +++ b/api/admin/index.js @@ -299,28 +299,64 @@ export async function GET(request) { const { searchParams } = new URL(request.url); const action = searchParams.get('action'); - if (action === 'card-counts') { - // Get card counts from database - const result = await sql.query(` - SELECT - game, - COUNT(*) as count - FROM cards - GROUP BY game - `); - - const counts = {}; - result.rows.forEach(row => { - counts[row.game] = parseInt(row.count); - }); - + // Simple test endpoint + if (action === 'test') { return NextResponse.json({ success: true, - counts, - total: Object.values(counts).reduce((sum, count) => sum + count, 0) + message: 'Admin API is working!', + timestamp: new Date().toISOString() }); } + if (action === 'card-counts') { + try { + // First check if the cards table exists + const tableCheck = await sql.query(` + SELECT EXISTS ( + SELECT FROM information_schema.tables + WHERE table_schema = 'public' + AND table_name = 'cards' + ); + `); + + if (!tableCheck.rows[0].exists) { + return NextResponse.json({ + success: true, + counts: {}, + total: 0, + message: 'Cards table does not exist yet' + }); + } + + // Get card counts from database + const result = await sql.query(` + SELECT + game, + COUNT(*) as count + FROM cards + GROUP BY game + `); + + const counts = {}; + result.rows.forEach(row => { + counts[row.game] = parseInt(row.count); + }); + + return NextResponse.json({ + success: true, + counts, + total: Object.values(counts).reduce((sum, count) => sum + count, 0) + }); + } catch (dbError) { + console.error('❌ Database error:', dbError); + return NextResponse.json({ + success: false, + error: 'Database error', + details: dbError.message + }, { status: 500 }); + } + } + if (action === 'user-stats') { // Get user statistics const result = await sql.query(`