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[allCoachs,setAllCoachs] = useState<Coach[]>([]);
|
||||||
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
||||||
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
||||||
const[allActivites,setAllActivites] = useState<Activite[]>([]);
|
|
||||||
|
|
||||||
|
|
||||||
async function updateAthletes() {
|
async function updateAthletes() {
|
||||||
|
|||||||
@@ -228,11 +228,18 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
|||||||
export async function getAllSessionsAPI():Promise<Session[]>{
|
export async function getAllSessionsAPI():Promise<Session[]>{
|
||||||
try {
|
try {
|
||||||
const response = await sessionService.getAll();
|
const response = await sessionService.getAll();
|
||||||
const sessions:Session[] = [];
|
const sessions = await Promise.all(
|
||||||
response.data.forEach(sessionDTO => {
|
response.data.map(async sessionDTO => {
|
||||||
sessions.push(new Session(sessionDTO));
|
const session = new Session(sessionDTO);
|
||||||
|
const coach = await getCoachByIdAPI(sessionDTO.coachId);
|
||||||
|
|
||||||
|
if (coach != null) {
|
||||||
|
session.coach = coach;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
});
|
|
||||||
return sessions;
|
return sessions;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching sessions:", error);
|
console.error("Error fetching sessions:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user