81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { ScoringService, JudgeService } from '@/lib/services/database-service';
|
|
|
|
// 獲取評審的評分任務
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const judgeId = searchParams.get('judgeId');
|
|
const competitionId = searchParams.get('competitionId');
|
|
|
|
console.log('🔍 評審任務API - 接收請求');
|
|
console.log('judgeId:', judgeId);
|
|
console.log('competitionId:', competitionId);
|
|
|
|
if (!judgeId) {
|
|
console.log('❌ 缺少評審ID');
|
|
return NextResponse.json({
|
|
success: false,
|
|
message: '缺少評審ID',
|
|
error: 'judgeId 為必填參數'
|
|
}, { status: 400 });
|
|
}
|
|
|
|
// 獲取評審信息
|
|
console.log('🔍 開始獲取評審信息...');
|
|
const judge = await JudgeService.getJudgeById(judgeId);
|
|
console.log('📊 評審信息查詢結果:', judge);
|
|
|
|
if (!judge) {
|
|
console.log('❌ 評審不存在');
|
|
return NextResponse.json({
|
|
success: false,
|
|
message: '評審不存在',
|
|
error: '找不到指定的評審'
|
|
}, { status: 404 });
|
|
}
|
|
|
|
// 獲取評審的評分任務
|
|
console.log('🔍 開始獲取評分任務...');
|
|
let scoringTasks = [];
|
|
|
|
if (competitionId) {
|
|
// 獲取特定競賽的評分任務
|
|
console.log('📊 獲取特定競賽的評分任務');
|
|
scoringTasks = await JudgeService.getJudgeScoringTasks(judgeId, competitionId);
|
|
} else {
|
|
// 獲取所有評分任務
|
|
console.log('📊 獲取所有評分任務');
|
|
scoringTasks = await JudgeService.getJudgeScoringTasks(judgeId);
|
|
}
|
|
|
|
console.log('📊 評分任務查詢結果:', scoringTasks);
|
|
|
|
const response = {
|
|
success: true,
|
|
message: '評分任務獲取成功',
|
|
data: {
|
|
judge: {
|
|
id: judge.id,
|
|
name: judge.name,
|
|
title: judge.title,
|
|
department: judge.department,
|
|
specialty: '評審專家'
|
|
},
|
|
tasks: scoringTasks
|
|
}
|
|
};
|
|
|
|
console.log('✅ API回應:', response);
|
|
return NextResponse.json(response);
|
|
|
|
} catch (error) {
|
|
console.error('❌ 獲取評分任務失敗:', error);
|
|
return NextResponse.json({
|
|
success: false,
|
|
message: '獲取評分任務失敗',
|
|
error: error instanceof Error ? error.message : '未知錯誤'
|
|
}, { status: 500 });
|
|
}
|
|
}
|