fix loading du coach des sessions
This commit is contained in:
@@ -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