修正競賽團隊編輯、個人賽顯示、團體賽顯示 bug

This commit is contained in:
2025-09-20 22:44:21 +08:00
parent c5bbec5ca8
commit 049b53fa43
15 changed files with 480 additions and 85 deletions

70
scripts/test-team-data.js Normal file
View File

@@ -0,0 +1,70 @@
const mysql = require('mysql2/promise');
async function testTeamData() {
const connection = await mysql.createConnection({
host: 'mysql.theaken.com',
port: 33306,
user: 'AI_Platform',
password: 'Aa123456',
database: 'db_AI_Platform',
charset: 'utf8mb4',
timezone: '+08:00'
});
try {
console.log('🔍 測試團隊數據查詢...');
// 使用與 getAllTeams 相同的查詢
const [results] = await connection.execute(`
SELECT t.*,
u.name as leader_name,
u.phone as leader_phone,
t.leader_id as leader,
COUNT(DISTINCT tm.id) as member_count,
COUNT(DISTINCT a.id) as app_count,
t.created_at as submissionDate
FROM teams t
LEFT JOIN users u ON t.leader_id = u.id
LEFT JOIN team_members tm ON t.id = tm.team_id
LEFT JOIN apps a ON t.id = a.team_id AND a.is_active = 1
WHERE t.is_active = 1
GROUP BY t.id, t.name, t.leader_id, t.department, t.contact_email, t.total_likes, t.is_active, t.created_at, t.updated_at, u.name, u.phone
ORDER BY t.created_at DESC
LIMIT 5
`);
console.log('📊 查詢結果:');
results.forEach((team, index) => {
console.log(`\n團隊 ${index + 1}:`);
console.log(` 名稱: ${team.name}`);
console.log(` 隊長ID: ${team.leader}`);
console.log(` 隊長姓名: ${team.leader_name || 'NULL'}`);
console.log(` 成員數量: ${team.member_count || 0}`);
console.log(` 提交日期: ${team.submissionDate || 'NULL'}`);
console.log(` 部門: ${team.department}`);
});
// 檢查特定團隊的成員
if (results.length > 0) {
const teamId = results[0].id;
const [members] = await connection.execute(`
SELECT tm.*, u.name as user_name
FROM team_members tm
LEFT JOIN users u ON tm.user_id = u.id
WHERE tm.team_id = ?
`, [teamId]);
console.log(`\n🔍 團隊 ${results[0].name} 的成員:`);
members.forEach(member => {
console.log(` - ${member.user_name} (${member.role})`);
});
}
} catch (error) {
console.error('❌ 錯誤:', error);
} finally {
await connection.end();
}
}
testTeamData();