Add test endpoint and better error handling for database issues

This commit is contained in:
Randall Stillwell 2025-07-23 08:22:16 -05:00
parent df5b3bfc44
commit 16228f8fa0

View file

@ -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(`