init
This commit is contained in:
32
app/api/kpi/route.ts
Normal file
32
app/api/kpi/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user