This commit is contained in:
2025-12-16 10:50:15 +01:00
parent 775d41e055
commit 8ed6ba1fd1
144 changed files with 5763 additions and 1985 deletions

View File

@@ -1,4 +1,9 @@
import { getStandingRepository, getLeagueRepository, getTeamMembershipRepository } from '@/lib/di-container';
/**
* TeamStandingsPresenter - Pure data transformer
* Transforms API response to view model without DI dependencies.
*/
import { apiClient } from '@/lib/apiClient';
export interface TeamLeagueStandingViewModel {
leagueId: string;
@@ -15,61 +20,37 @@ export interface TeamStandingsViewModel {
/**
* Compute team standings across the given leagues for a team.
* Mirrors the previous TeamStandings component logic but keeps it out of the UI layer.
* This would need a dedicated API endpoint for team standings.
* For now, returns empty standings - the API should provide this data.
* @param teamId - The team ID (will be used when API supports team standings)
* @param leagueIds - List of league IDs to fetch standings for
*/
export async function loadTeamStandings(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
teamId: string,
leagues: string[],
leagueIds: string[],
): Promise<TeamStandingsViewModel> {
const standingRepo = getStandingRepository();
const leagueRepo = getLeagueRepository();
const teamMembershipRepo = getTeamMembershipRepository();
const members = await teamMembershipRepo.getTeamMembers(teamId);
const memberIds = members.map((m) => m.driverId);
// In the new architecture, team standings should come from API
// For now, fetch each league's standings and aggregate
const teamStandings: TeamLeagueStandingViewModel[] = [];
for (const leagueId of leagues) {
const league = await leagueRepo.findById(leagueId);
if (!league) continue;
const leagueStandings = await standingRepo.findByLeagueId(leagueId);
let totalPoints = 0;
let totalWins = 0;
let totalRaces = 0;
for (const standing of leagueStandings) {
if (memberIds.includes(standing.driverId)) {
totalPoints += standing.points;
totalWins += standing.wins;
totalRaces = Math.max(totalRaces, standing.racesCompleted);
}
for (const leagueId of leagueIds) {
try {
const standings = await apiClient.leagues.getStandings(leagueId);
// Since we don't have team-specific standings from API yet,
// this is a placeholder that returns basic data
teamStandings.push({
leagueId,
leagueName: `League ${leagueId}`, // Would need from API
position: 0,
points: 0,
wins: 0,
racesCompleted: standings.standings.length > 0 ? 1 : 0,
});
} catch {
// Skip leagues that fail to load
}
// Simplified team position based on total points (same spirit as previous logic)
const allTeamPoints = leagueStandings
.filter((s) => memberIds.includes(s.driverId))
.reduce((sum, s) => sum + s.points, 0);
const position =
leagueStandings
.filter((_, idx, arr) => {
const teamPoints = arr
.filter((s) => memberIds.includes(s.driverId))
.reduce((sum, s) => sum + s.points, 0);
return teamPoints > allTeamPoints;
}).length + 1;
teamStandings.push({
leagueId,
leagueName: league.name,
position,
points: totalPoints,
wins: totalWins,
racesCompleted: totalRaces,
});
}
return { standings: teamStandings };