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

30 lines
1.1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getAllPolls } from '@/lib/polls'
const CATEGORIES = [
{ id: 'finance', name: 'Finance', emoji: '💰', featured: true },
{ id: 'crypto', name: 'Crypto', emoji: '₿', featured: true },
{ id: 'sports', name: 'Sports', emoji: '⚽', featured: true },
{ id: 'politics', name: 'Politics', emoji: '🗳️', featured: false },
{ id: 'entertainment', name: 'Entertainment', emoji: '🎬', featured: false },
{ id: 'technology', name: 'Technology', emoji: '💻', featured: false },
{ id: 'weather', name: 'Weather', emoji: '🌤️', featured: false },
{ id: 'other', name: 'Other', emoji: '📊', featured: false }
]
export async function GET(req: NextRequest) {
try {
const polls = await getAllPolls()
const categoriesWithCounts = CATEGORIES.map(cat => ({
...cat,
count: polls.filter(p => p.category === cat.id).length
}))
return NextResponse.json({ categories: categoriesWithCounts })
} catch (error) {
console.error('Categories API error:', error)
return NextResponse.json({ categories: CATEGORIES.map(c => ({ ...c, count: 0 })) })
}
}