40 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import {
decideTaskDetailChange,
TaskDetailChangeApprovalError,
} from '@/lib/task-detail-change-approval'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
export const maxDuration = 10800
type RouteParams = { params: { id: string } }
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const session = await getServerSession(authOptions)
const user = session?.user as { id?: string; role?: string; isSuperAdmin?: boolean } | undefined
if (!user?.id) return NextResponse.json({ success: false, error: '未登录' }, { status: 401 })
const body = await request.json().catch(() => null) as { decision?: unknown } | null
const decision = String(body?.decision || '')
if (decision !== 'approve' && decision !== 'reject') {
return NextResponse.json({ success: false, error: '请选择批准或否决' }, { status: 400 })
}
const data = await decideTaskDetailChange(params.id, {
id: user.id,
role: user.role || null,
isSuperAdmin: Boolean(user.isSuperAdmin),
}, decision)
return NextResponse.json({ success: true, data })
} catch (error) {
if (error instanceof TaskDetailChangeApprovalError) {
return NextResponse.json({ success: false, error: error.message }, { status: error.statusCode })
}
console.error('[task-detail-change] decision error:', error)
return NextResponse.json({ success: false, error: '确认图片变更失败,请稍后重试' }, { status: 500 })
}
}