43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { getServerSession } from 'next-auth'
|
|
import { NextResponse } from 'next/server'
|
|
import { authOptions } from '@/lib/auth'
|
|
import {
|
|
assertBrandCenterDashboardAccess,
|
|
BrandCenterDashboardAccessError,
|
|
} from '@/lib/brand-center-dashboard-access'
|
|
import { PerformanceSurveyApiError } from '@/lib/performance-survey-service'
|
|
import {
|
|
WorkReviewApiError,
|
|
getFirstPassReviewSummary,
|
|
} from '@/lib/work-review-service'
|
|
|
|
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)
|
|
await assertBrandCenterDashboardAccess(session)
|
|
const data = await getFirstPassReviewSummary(session)
|
|
return NextResponse.json({ success: true, data }, { headers: PRIVATE_HEADERS })
|
|
} catch (error) {
|
|
if (error instanceof BrandCenterDashboardAccessError || error instanceof WorkReviewApiError || error instanceof PerformanceSurveyApiError) {
|
|
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 },
|
|
)
|
|
}
|
|
}
|