Files
wish-pool/app/api/wishes/test-realtime/route.ts
2025-10-07 11:46:05 +08:00

50 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextRequest, NextResponse } from 'next/server'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export async function GET(request: NextRequest) {
try {
console.log('🔍 測試即時數據獲取...')
// 簡單測試獲取前5個困擾案例
const wishes = await prisma.wish.findMany({
where: {
status: 'active'
},
orderBy: {
id: 'desc'
},
take: 5,
select: {
id: true,
title: true,
isPublic: true,
createdAt: true
}
})
console.log(`✅ 成功獲取 ${wishes.length} 筆困擾案例`)
// 轉換 BigInt 為 Number
const formattedWishes = wishes.map((wish: any) => ({
...wish,
id: Number(wish.id),
createdAt: wish.createdAt.toISOString()
}))
return NextResponse.json({
success: true,
data: formattedWishes,
message: `成功獲取 ${wishes.length} 筆困擾案例`
})
} catch (error) {
console.error('API Error:', error)
return NextResponse.json(
{ success: false, error: error.message },
{ status: 500 }
)
}
}