fix loading du coach des sessions
This commit is contained in:
@@ -23,7 +23,6 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
const[allCoachs,setAllCoachs] = useState<Coach[]>([]);
|
||||
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
||||
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
||||
const[allActivites,setAllActivites] = useState<Activite[]>([]);
|
||||
|
||||
|
||||
async function updateAthletes() {
|
||||
|
||||
@@ -228,11 +228,18 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
export async function getAllSessionsAPI():Promise<Session[]>{
|
||||
try {
|
||||
const response = await sessionService.getAll();
|
||||
const sessions:Session[] = [];
|
||||
response.data.forEach(sessionDTO => {
|
||||
sessions.push(new Session(sessionDTO));
|
||||
|
||||
});
|
||||
const sessions = await Promise.all(
|
||||
response.data.map(async sessionDTO => {
|
||||
const session = new Session(sessionDTO);
|
||||
const coach = await getCoachByIdAPI(sessionDTO.coachId);
|
||||
|
||||
if (coach != null) {
|
||||
session.coach = coach;
|
||||
}
|
||||
return session;
|
||||
})
|
||||
);
|
||||
|
||||
return sessions;
|
||||
} catch (error) {
|
||||
console.error("Error fetching sessions:", error);
|
||||
|
||||
Reference in New Issue
Block a user