Files
ExecuBoard/app/api/kpi/[id]/route.ts
2025-08-01 00:55:05 +08:00

31 lines
894 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { kpiService } from '@/lib/database'
// PUT - 更新 KPI
export async function PUT(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const body = await request.json()
const kpi = await kpiService.updateKPI(params.id, body)
return NextResponse.json(kpi)
} catch (error) {
console.error('更新 KPI 失敗:', error)
return NextResponse.json({ error: '更新 KPI 失敗' }, { status: 500 })
}
}
// DELETE - 刪除 KPI
export async function DELETE(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
await kpiService.deleteKPI(params.id)
return NextResponse.json({ message: 'KPI 刪除成功' })
} catch (error) {
console.error('刪除 KPI 失敗:', error)
return NextResponse.json({ error: '刪除 KPI 失敗' }, { status: 500 })
}
}