fix: improve error handling and type safety
- Replaced 'any' types with proper TypeScript types - Improved error handling with instanceof checks - Removed unused imports (calculateExpectedTeamScore) - Updated error messages to be more descriptive - Removed deprecated eslint.config.mjs file
This commit is contained in:
@@ -4,18 +4,7 @@ import { canManageTournament } from "@/lib/permissions";
|
||||
import { getSession } from "@/lib/auth-simple";
|
||||
import { calculateTeamElo, calculateTeamEloChange } from "@/lib/elo-utils";
|
||||
|
||||
interface GameEntry {
|
||||
round: number
|
||||
table: string
|
||||
player1: string
|
||||
player2: string
|
||||
score1: number
|
||||
player3: string
|
||||
player4: string
|
||||
score2: number
|
||||
}
|
||||
|
||||
const K_FACTOR = 32;
|
||||
const K_FACTOR = 32; // Standard K-factor for Elo calculations
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
@@ -139,15 +128,16 @@ export async function POST(
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// Participant already exists, which is fine
|
||||
console.log(`Participant ${player.id} already exists in tournament ${tournamentId}`);
|
||||
}
|
||||
}
|
||||
|
||||
importedCount++;
|
||||
} catch (err: any) {
|
||||
errors.push(`Game ${index + 1}: ${err.message}`);
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : "Unknown error";
|
||||
errors.push(`Game ${index + 1}: ${message}`);
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
@@ -157,10 +147,11 @@ export async function POST(
|
||||
errorCount,
|
||||
errors: errors.length > 0 ? errors : undefined,
|
||||
});
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
console.error("Bulk game submission error:", error);
|
||||
const message = error instanceof Error ? error.message : "Failed to submit games";
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Failed to submit games" },
|
||||
{ error: message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user