修正競賽團隊編輯、個人賽顯示、團體賽顯示 bug
This commit is contained in:
@@ -52,11 +52,15 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// 獲取所有活躍的應用,編輯團隊時顯示所有應用(包括已綁定的)
|
||||
// 使用 is_active = 1 因為數據庫中存儲的是數字 1
|
||||
// 與 users 表 JOIN 獲取創建者姓名
|
||||
let sql = `
|
||||
SELECT id, name, description, category, type, icon, icon_color, app_url, creator_id, team_id
|
||||
FROM apps
|
||||
WHERE is_active = 1
|
||||
ORDER BY created_at DESC
|
||||
SELECT a.id, a.name, a.description, a.category, a.type, a.icon, a.icon_color, a.app_url,
|
||||
a.creator_id, a.team_id, a.created_at as submissionDate,
|
||||
u.name as creator_name
|
||||
FROM apps a
|
||||
LEFT JOIN users u ON a.creator_id = u.id
|
||||
WHERE a.is_active = 1
|
||||
ORDER BY a.created_at DESC
|
||||
`;
|
||||
|
||||
const params: any[] = [];
|
||||
@@ -72,17 +76,17 @@ export async function GET(request: NextRequest) {
|
||||
console.log('⚠️ 沒有找到 is_active = 1 的應用,嘗試其他查詢條件...');
|
||||
|
||||
// 嘗試 is_active = TRUE
|
||||
const sqlTrue = sql.replace('WHERE is_active = 1', 'WHERE 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 is_active = 1', 'WHERE 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 is_active = 1', 'WHERE 1=1');
|
||||
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, '個應用');
|
||||
|
||||
|
@@ -10,20 +10,48 @@ export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const competitions = await CompetitionService.getAllCompetitions();
|
||||
|
||||
// 動態計算每個競賽的狀態
|
||||
const now = new Date();
|
||||
const competitionsWithCalculatedStatus = competitions.map(competition => {
|
||||
const startDate = new Date(competition.start_date);
|
||||
const endDate = new Date(competition.end_date);
|
||||
|
||||
let calculatedStatus = competition.status;
|
||||
|
||||
// 確保日期比較的準確性,使用 UTC 時間避免時區問題
|
||||
const nowUTC = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
|
||||
const startDateUTC = new Date(startDate.getTime() + startDate.getTimezoneOffset() * 60000);
|
||||
const endDateUTC = new Date(endDate.getTime() + endDate.getTimezoneOffset() * 60000);
|
||||
|
||||
// 根據實際日期計算狀態
|
||||
if (nowUTC < startDateUTC) {
|
||||
calculatedStatus = 'upcoming'; // 即將開始
|
||||
} else if (nowUTC >= startDateUTC && nowUTC <= endDateUTC) {
|
||||
calculatedStatus = 'active'; // 進行中
|
||||
} else if (nowUTC > endDateUTC) {
|
||||
calculatedStatus = 'completed'; // 已完成
|
||||
}
|
||||
|
||||
return {
|
||||
...competition,
|
||||
status: calculatedStatus
|
||||
};
|
||||
});
|
||||
|
||||
// 計算統計數據
|
||||
const stats = {
|
||||
total: competitions.length,
|
||||
upcoming: competitions.filter(c => c.status === 'upcoming').length,
|
||||
active: competitions.filter(c => c.status === 'active' || c.status === 'ongoing').length,
|
||||
ongoing: competitions.filter(c => c.status === 'ongoing').length,
|
||||
judging: competitions.filter(c => c.status === 'judging').length,
|
||||
completed: competitions.filter(c => c.status === 'completed').length,
|
||||
individual: competitions.filter(c => c.type === 'individual').length,
|
||||
team: competitions.filter(c => c.type === 'team').length,
|
||||
mixed: competitions.filter(c => c.type === 'mixed').length,
|
||||
proposal: competitions.filter(c => c.type === 'proposal').length,
|
||||
currentYear: competitions.filter(c => c.year === new Date().getFullYear()).length,
|
||||
thisMonth: competitions.filter(c =>
|
||||
total: competitionsWithCalculatedStatus.length,
|
||||
upcoming: competitionsWithCalculatedStatus.filter(c => c.status === 'upcoming').length,
|
||||
active: competitionsWithCalculatedStatus.filter(c => c.status === 'active' || c.status === 'ongoing').length,
|
||||
ongoing: competitionsWithCalculatedStatus.filter(c => c.status === 'ongoing').length,
|
||||
judging: competitionsWithCalculatedStatus.filter(c => c.status === 'judging').length,
|
||||
completed: competitionsWithCalculatedStatus.filter(c => c.status === 'completed').length,
|
||||
individual: competitionsWithCalculatedStatus.filter(c => c.type === 'individual').length,
|
||||
team: competitionsWithCalculatedStatus.filter(c => c.type === 'team').length,
|
||||
mixed: competitionsWithCalculatedStatus.filter(c => c.type === 'mixed').length,
|
||||
proposal: competitionsWithCalculatedStatus.filter(c => c.type === 'proposal').length,
|
||||
currentYear: competitionsWithCalculatedStatus.filter(c => c.year === new Date().getFullYear()).length,
|
||||
thisMonth: competitionsWithCalculatedStatus.filter(c =>
|
||||
c.year === new Date().getFullYear() &&
|
||||
c.month === new Date().getMonth() + 1
|
||||
).length
|
||||
|
Reference in New Issue
Block a user