2026-09-02 11:44:55 +08:00

31 lines
1.1 KiB
TypeScript

import { getServerSession } from 'next-auth'
import { NextResponse } from 'next/server'
import { authOptions } from '@/lib/auth'
import { DingWorkflowMetricApiError, getTeamCapacityInsights } from '@/lib/ding-workflow-sync'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
export const revalidate = 0
const PRIVATE_HEADERS = { 'Cache-Control': 'private, no-store, max-age=0' }
export async function GET() {
try {
const session = await getServerSession(authOptions)
const data = await getTeamCapacityInsights(session)
return NextResponse.json({ success: true, data }, { headers: PRIVATE_HEADERS })
} catch (error) {
if (error instanceof DingWorkflowMetricApiError) {
return NextResponse.json(
{ success: false, error: error.message },
{ status: error.status, headers: PRIVATE_HEADERS },
)
}
console.error('[department-dashboard] 团队产能读取失败:', error)
return NextResponse.json(
{ success: false, error: '团队产能读取失败,请稍后重试' },
{ status: 500, headers: PRIVATE_HEADERS },
)
}
}