This commit is contained in:
2025-08-01 00:55:05 +08:00
commit d96b0a511d
96 changed files with 14825 additions and 0 deletions

32
app/api/kpi/route.ts Normal file
View File

@@ -0,0 +1,32 @@
import { NextRequest, NextResponse } from 'next/server'
import { kpiService } from '@/lib/database'
// GET - 獲取 KPI 列表
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
if (!userId) {
return NextResponse.json({ error: '缺少用戶 ID' }, { status: 400 })
}
const kpis = await kpiService.getKPIsByUser(userId)
return NextResponse.json(kpis)
} catch (error) {
console.error('獲取 KPI 失敗:', error)
return NextResponse.json({ error: '獲取 KPI 失敗' }, { status: 500 })
}
}
// POST - 創建新 KPI
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const kpi = await kpiService.createKPI(body)
return NextResponse.json(kpi, { status: 201 })
} catch (error) {
console.error('創建 KPI 失敗:', error)
return NextResponse.json({ error: '創建 KPI 失敗' }, { status: 500 })
}
}