2025-12-08 16:31:30 +03:00

55 lines
2.1 KiB
TypeScript

import { NextResponse } from 'next/server'
import { getTodaysPoll } from '@/lib/db/polls'
export async function GET() {
try {
console.log('[API] Getting today\'s poll...')
console.log('[API] DATABASE_URL exists:', !!process.env.DATABASE_URL)
const poll = await getTodaysPoll()
if (poll) {
console.log('[API] Poll found from database')
return NextResponse.json(poll)
}
// Fallback: return hardcoded poll if database fails
console.log('[API] No poll from database, returning fallback')
const fallbackPoll = {
id: '875ddaa4-dbe5-4aa5-86a0-c41bfff659e8',
creatorFid: 1,
creatorAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
question: 'Tomorrow 1 USD = ? TL',
description: 'Predict tomorrow\'s USD/TRY exchange rate',
emoji: '๐Ÿ’ต',
startTime: Math.floor(Date.now() / 1000),
endTime: Math.floor(Date.now() / 1000) + 86400,
status: 'active',
verificationType: 'manual',
verificationConfig: {},
correctOptionId: null,
verifiedAt: null,
verificationProof: null,
totalPot: 0,
protocolFee: 0,
creationFee: 5,
winnersCount: 0,
distributedAt: null,
distributionTxHashes: null,
createdAt: Math.floor(Date.now() / 1000),
updatedAt: new Date().toISOString(),
options: [
{ id: 'fbfe853d-a175-47be-9d7e-6ba55c21a440', text: '34.00 - 34.50 TL', emoji: '๐Ÿ“‰', votes: 0, totalAmount: 0 },
{ id: 'c9b08f14-90ae-41af-af57-343e4b358078', text: '34.50 - 35.00 TL', emoji: '๐Ÿ“Š', votes: 0, totalAmount: 0 },
{ id: 'dc3c9f7b-8cd7-4ba8-8c8c-8c91dd423b19', text: '35.00 - 35.50 TL', emoji: '๐Ÿ“ˆ', votes: 0, totalAmount: 0 },
{ id: '57822915-5d8c-4a8d-94ad-065bfb2599cf', text: '35.50+ TL', emoji: '๐Ÿš€', votes: 0, totalAmount: 0 },
]
}
return NextResponse.json(fallbackPoll)
} catch (error) {
console.error('[API] Failed to get today\'s poll:', error)
return NextResponse.json({ error: 'Failed to fetch poll', details: String(error) }, { status: 500 })
}
}