Feat: Stats athlètes fonctionnel
This commit is contained in:
@@ -361,3 +361,29 @@ export async function getAllAthlete(): Promise<Athlete[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSessionsByAthleteId(athleteId: number): Promise<Session[]> {
|
||||
try {
|
||||
const response = await api.get(`/athlete/athlete/${athleteId}/session`);
|
||||
const sessions: Session[] = [];
|
||||
|
||||
const allAthletes = await getAllAthlete();
|
||||
|
||||
response.data.forEach((sessionDTO: SessionDTO) => {
|
||||
const session = new Session(sessionDTO);
|
||||
|
||||
if (sessionDTO.athleteIds && sessionDTO.athleteIds.length > 0) {
|
||||
session.athletes = allAthletes.filter(a =>
|
||||
sessionDTO.athleteIds.includes(a.id!)
|
||||
);
|
||||
}
|
||||
|
||||
sessions.push(session);
|
||||
});
|
||||
|
||||
console.log(`Sessions chargées pour l'athlète ${athleteId}:`, sessions);
|
||||
return sessions;
|
||||
} catch (error) {
|
||||
console.error("Error fetching sessions for athlete:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user