完成評審評分機制
This commit is contained in:
118
SCORING-FORM-FIX.md
Normal file
118
SCORING-FORM-FIX.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# 評分表單修復報告
|
||||
|
||||
## 問題描述
|
||||
手動評審評分表單無法選擇評審和參賽者,無法進行評分操作。
|
||||
|
||||
## 根本原因
|
||||
1. 前端組件使用空的mock數據而非從後端API獲取真實數據
|
||||
2. 評審和參賽者選項沒有與資料庫整合
|
||||
3. 缺少團隊評分支持
|
||||
|
||||
## 修復內容
|
||||
|
||||
### 1. 前端組件修復 (`components/admin/scoring-management.tsx`)
|
||||
|
||||
#### 新增狀態管理
|
||||
```typescript
|
||||
// 新增狀態:從後端獲取的評審和參賽者數據
|
||||
const [competitionJudges, setCompetitionJudges] = useState<any[]>([])
|
||||
const [competitionParticipants, setCompetitionParticipants] = useState<any[]>([])
|
||||
```
|
||||
|
||||
#### 新增數據載入函數
|
||||
```typescript
|
||||
const loadCompetitionData = async () => {
|
||||
// 載入競賽評審
|
||||
const judgesResponse = await fetch(`/api/competitions/${selectedCompetition.id}/judges`)
|
||||
|
||||
// 載入競賽參賽者(應用和團隊)
|
||||
const [appsResponse, teamsResponse] = await Promise.all([
|
||||
fetch(`/api/competitions/${selectedCompetition.id}/apps`),
|
||||
fetch(`/api/competitions/${selectedCompetition.id}/teams`)
|
||||
])
|
||||
}
|
||||
```
|
||||
|
||||
#### 更新評審選擇器
|
||||
- 從 `judges` 改為 `competitionJudges`
|
||||
- 顯示評審的職稱和部門信息
|
||||
|
||||
#### 更新參賽者選擇器
|
||||
- 從mock數據改為 `competitionParticipants`
|
||||
- 支持個人和團隊兩種參賽者類型
|
||||
- 顯示創作者/隊長信息
|
||||
|
||||
### 2. 後端API修復
|
||||
|
||||
#### 新增團隊評分支持 (`lib/services/database-service.ts`)
|
||||
```typescript
|
||||
// 提交團隊評分(使用應用評分表,但標記為團隊類型)
|
||||
static async submitTeamScore(scoreData: Omit<AppJudgeScore, 'id' | 'submitted_at'> & { teamId: string }): Promise<AppJudgeScore>
|
||||
```
|
||||
|
||||
#### 更新API端點 (`app/api/admin/scoring/route.ts`)
|
||||
- 支持 `team` 參賽者類型
|
||||
- 根據參賽者類型選擇適當的評分方法
|
||||
|
||||
### 3. 評分提交邏輯修復
|
||||
|
||||
#### 動態參賽者類型判斷
|
||||
```typescript
|
||||
const participantType = selectedParticipant?.type === 'individual' ? 'app' :
|
||||
selectedParticipant?.type === 'team' ? 'team' : 'proposal'
|
||||
```
|
||||
|
||||
## 修復後的功能
|
||||
|
||||
### ✅ 評審選擇
|
||||
- 從資料庫載入競賽的評審列表
|
||||
- 顯示評審姓名、職稱、部門
|
||||
- 支持選擇評審進行評分
|
||||
|
||||
### ✅ 參賽者選擇
|
||||
- 從資料庫載入競賽的應用和團隊
|
||||
- 支持個人賽和團隊賽參賽者
|
||||
- 顯示參賽者名稱和創作者信息
|
||||
|
||||
### ✅ 評分提交
|
||||
- 支持應用評分 (participantType: 'app')
|
||||
- 支持提案評分 (participantType: 'proposal')
|
||||
- 支持團隊評分 (participantType: 'team')
|
||||
- 自動計算總分
|
||||
- 保存評審意見
|
||||
|
||||
### ✅ 數據整合
|
||||
- 完全與後端資料庫整合
|
||||
- 實時載入競賽相關數據
|
||||
- 支持評分記錄的CRUD操作
|
||||
|
||||
## 測試驗證
|
||||
|
||||
### 資料庫測試
|
||||
```bash
|
||||
node scripts/test-scoring.js
|
||||
```
|
||||
|
||||
### API功能測試
|
||||
```bash
|
||||
node scripts/test-scoring-form.js
|
||||
```
|
||||
|
||||
## 使用方式
|
||||
|
||||
1. 管理員選擇競賽
|
||||
2. 系統自動載入該競賽的評審和參賽者
|
||||
3. 點擊「手動輸入評分」
|
||||
4. 選擇評審和參賽者
|
||||
5. 填寫評分項目和意見
|
||||
6. 提交評分到資料庫
|
||||
|
||||
## 技術特點
|
||||
|
||||
- **完全整合**:前端與後端資料庫完全整合
|
||||
- **類型安全**:支持多種參賽者類型
|
||||
- **實時數據**:動態載入競賽相關數據
|
||||
- **用戶友好**:清晰的界面和錯誤提示
|
||||
- **可擴展**:易於添加新的評分類型
|
||||
|
||||
修復完成後,手動評審評分功能已完全可用,支持選擇評審和參賽者進行評分操作。
|
Reference in New Issue
Block a user