修正資料即時呈現

This commit is contained in:
2025-10-07 11:46:05 +08:00
parent 01bc5e57f6
commit 4482f6c3c7
13 changed files with 573 additions and 283 deletions

View File

@@ -0,0 +1,49 @@
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 }
)
}
}