修正評審評分清單失敗問題

This commit is contained in:
2025-09-21 01:30:26 +08:00
parent 049b53fa43
commit a36ab3c98d
17 changed files with 251 additions and 274 deletions

View File

@@ -7,51 +7,10 @@ import { db } from '@/lib/database';
export async function GET(request: NextRequest) {
try {
console.log('🚀 ========== 應用 API 開始執行 ==========');
const { searchParams } = new URL(request.url);
const teamId = searchParams.get('teamId');
console.log('🔍 獲取可用應用列表, teamId:', teamId);
console.log('🔍 請求 URL:', request.url);
// 先檢查所有應用
console.log('📊 開始檢查數據庫...');
const allAppsSql = `SELECT COUNT(*) as count FROM apps`;
const allAppsResult = await db.query(allAppsSql);
console.log('📊 數據庫中應用總數:', allAppsResult[0].count);
// 檢查活躍應用
const activeAppsSql = `SELECT COUNT(*) as count FROM apps WHERE is_active = TRUE`;
const activeAppsResult = await db.query(activeAppsSql);
console.log('✅ 活躍應用數量 (is_active = TRUE):', activeAppsResult[0].count);
// 檢查所有應用的 is_active 值
const allAppsWithStatusSql = `SELECT id, name, is_active, team_id FROM apps LIMIT 5`;
const allAppsWithStatusResult = await db.query(allAppsWithStatusSql);
console.log('📋 前5個應用的狀態:', allAppsWithStatusResult);
// 檢查是否有 is_active = 1 的應用
const activeAppsWith1Sql = `SELECT COUNT(*) as count FROM apps WHERE is_active = 1`;
const activeAppsWith1Result = await db.query(activeAppsWith1Sql);
console.log('✅ is_active = 1 的應用數量:', activeAppsWith1Result[0].count);
// 檢查是否有 is_active = '1' 的應用(字符串)
const activeAppsWithStringSql = `SELECT COUNT(*) as count FROM apps WHERE is_active = '1'`;
const activeAppsWithStringResult = await db.query(activeAppsWithStringSql);
console.log('✅ is_active = "1" 的應用數量:', activeAppsWithStringResult[0].count);
// 檢查沒有團隊的應用
const noTeamAppsSql = `SELECT COUNT(*) as count FROM apps WHERE is_active = 1 AND team_id IS NULL`;
const noTeamAppsResult = await db.query(noTeamAppsSql);
console.log('🔓 沒有團隊的應用數量:', noTeamAppsResult[0].count);
// 檢查屬於其他團隊的應用
const otherTeamAppsSql = `SELECT COUNT(*) as count FROM apps WHERE is_active = 1 AND team_id IS NOT NULL AND team_id != ?`;
const otherTeamAppsResult = await db.query(otherTeamAppsSql, [teamId || '']);
console.log('🔓 屬於其他團隊的應用數量:', otherTeamAppsResult[0].count);
// 獲取所有活躍的應用,編輯團隊時顯示所有應用(包括已綁定的)
// 使用 is_active = 1 因為數據庫中存儲的是數字 1
// 與 users 表 JOIN 獲取創建者姓名
let sql = `
SELECT a.id, a.name, a.description, a.category, a.type, a.icon, a.icon_color, a.app_url,
@@ -65,48 +24,36 @@ export async function GET(request: NextRequest) {
const params: any[] = [];
console.log('📝 執行的 SQL:', sql);
console.log('📝 參數:', params);
const apps = await db.query(sql, params);
console.log('📊 查詢結果:', apps.length, '個應用');
// 如果沒有結果,嘗試不同的查詢條件
if (apps.length === 0) {
console.log('⚠️ 沒有找到 is_active = 1 的應用,嘗試其他查詢條件...');
// 嘗試 is_active = TRUE
const sqlTrue = sql.replace('WHERE a.is_active = 1', 'WHERE a.is_active = TRUE');
const appsTrue = await db.query(sqlTrue, params);
console.log('📊 is_active = TRUE 查詢結果:', appsTrue.length, '個應用');
// 嘗試 is_active = '1'
const sqlString = sql.replace('WHERE a.is_active = 1', 'WHERE a.is_active = "1"');
const appsString = await db.query(sqlString, params);
console.log('📊 is_active = "1" 查詢結果:', appsString.length, '個應用');
// 嘗試沒有 is_active 條件
const sqlNoFilter = sql.replace('WHERE a.is_active = 1', 'WHERE 1=1');
const appsNoFilter = await db.query(sqlNoFilter, params);
console.log('📊 無 is_active 過濾查詢結果:', appsNoFilter.length, '個應用');
// 使用有結果的查詢
if (appsTrue.length > 0) {
console.log('✅ 使用 is_active = TRUE 的結果');
return NextResponse.json({
success: true,
message: '可用應用列表獲取成功',
data: appsTrue
});
} else if (appsString.length > 0) {
console.log('✅ 使用 is_active = "1" 的結果');
return NextResponse.json({
success: true,
message: '可用應用列表獲取成功',
data: appsString
});
} else if (appsNoFilter.length > 0) {
console.log('✅ 使用無過濾條件的結果');
return NextResponse.json({
success: true,
message: '可用應用列表獲取成功',
@@ -115,7 +62,6 @@ export async function GET(request: NextRequest) {
}
}
console.log('🚀 ========== 應用 API 執行完成 ==========');
return NextResponse.json({
success: true,
message: '可用應用列表獲取成功',
@@ -130,4 +76,4 @@ export async function GET(request: NextRequest) {
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}
}

View File

@@ -7,19 +7,14 @@ import { db } from '@/lib/database';
export async function GET(request: NextRequest) {
try {
console.log('🧪 開始測試資料庫連接...');
// 測試基本查詢
const result = await db.query('SELECT 1 as test');
console.log('✅ 基本查詢成功:', result);
// 測試競賽表
const competitions = await db.query('SELECT id, name, type FROM competitions WHERE is_active = TRUE LIMIT 3');
console.log('✅ 競賽查詢成功:', competitions);
// 測試評審表
const judges = await db.query('SELECT id, name, title FROM judges WHERE is_active = TRUE LIMIT 3');
console.log('✅ 評審查詢成功:', judges);
return NextResponse.json({
success: true,

View File

@@ -14,7 +14,6 @@ export default function DebugScoringPage() {
const addLog = (message: string) => {
setLogs(prev => [...prev, `${new Date().toLocaleTimeString()}: ${message}`])
console.log(message)
}
// 載入競賽列表

View File

@@ -63,7 +63,7 @@ export default function JudgeScoringPage() {
try {
// 獲取評審的評分任務
const response = await fetch(`/api/judge/scoring-tasks?judgeId=${judgeId}`)
const response = await fetch(`/api/judge/scoring-tasks?judgeId=${judgeId}&competitionId=0fffae9a-9539-11f0-b5d9-6e36c63cdb98`)
const data = await response.json()
if (data.success) {
@@ -89,7 +89,7 @@ export default function JudgeScoringPage() {
const loadCompetitionRules = async () => {
try {
// 使用正確的競賽ID
const response = await fetch('/api/competitions/be47d842-91f1-11f0-8595-bd825523ae01/rules')
const response = await fetch('/api/competitions/0fffae9a-9539-11f0-b5d9-6e36c63cdb98/rules')
const data = await response.json()
if (data.success) {
@@ -169,7 +169,7 @@ export default function JudgeScoringPage() {
participantType: 'app',
scores: scores,
comments: comments.trim(),
competitionId: 'be47d842-91f1-11f0-8595-bd825523ae01', // 正確的競賽ID
competitionId: '0fffae9a-9539-11f0-b5d9-6e36c63cdb98', // 正確的競賽ID
isEdit: selectedItem.status === "completed", // 如果是重新評分,標記為編輯模式
recordId: selectedItem.status === "completed" ? selectedItem.id : null
})
@@ -298,11 +298,6 @@ export default function JudgeScoringPage() {
</>
)}
</Button>
<div className="text-center text-sm text-gray-500">
<p>ID範例j1, j2, j3, j4, j5</p>
<p>judge2024</p>
</div>
</CardContent>
</Card>
</div>

View File

@@ -217,7 +217,6 @@ export default function AIShowcasePlatform() {
if (statsResponse.ok) {
const statsData = await statsResponse.json()
if (statsData.success) {
console.log(`載入應用 ${app.name} 的統計數據:`, statsData.data)
return { ...app, ...statsData.data }
}
}
@@ -365,7 +364,6 @@ export default function AIShowcasePlatform() {
const handleTryApp = async (appId: string) => {
await incrementViewCount(appId)
addToRecentApps(appId)
console.log(`Opening app ${appId}`)
}
const getCompetitionTypeIcon = (type: string) => {

View File

@@ -14,7 +14,6 @@ export default function TestManualScoringPage() {
const loadCompetitionData = async () => {
try {
console.log('🔍 開始載入競賽數據...')
// 載入競賽信息
const competitionResponse = await fetch('/api/competitions/be4b0a71-91f1-11f0-bb38-4adff2d0e33e')
@@ -22,7 +21,6 @@ export default function TestManualScoringPage() {
if (competitionData.success) {
setCompetition(competitionData.data.competition)
console.log('✅ 競賽載入成功:', competitionData.data.competition.name)
}
// 載入團隊數據
@@ -31,15 +29,6 @@ export default function TestManualScoringPage() {
if (teamsData.success) {
setTeams(teamsData.data.teams)
console.log('✅ 團隊載入成功:', teamsData.data.teams.length, '個團隊')
teamsData.data.teams.forEach((team: any) => {
console.log(` - ${team.name}: ${team.apps?.length || 0} 個APP`)
if (team.apps && team.apps.length > 0) {
team.apps.forEach((app: any) => {
console.log(` * ${app.name} (${app.id})`)
})
}
})
}
} catch (error) {