Add test endpoint and better error handling for database issues
This commit is contained in:
parent
df5b3bfc44
commit
16228f8fa0
1 changed files with 53 additions and 17 deletions
|
|
@ -299,7 +299,35 @@ export async function GET(request) {
|
|||
const { searchParams } = new URL(request.url);
|
||||
const action = searchParams.get('action');
|
||||
|
||||
// Simple test endpoint
|
||||
if (action === 'test') {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
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
|
||||
|
|
@ -319,6 +347,14 @@ export async function GET(request) {
|
|||
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') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue