correction bug admin + lecture de toute les session dans l'edt pour l'admin
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import api, { activiteService, athleteService, coachService, sessionService } from "./api";
|
||||
import api, { activiteService, adminService, athleteService, coachService, sessionService } from "./api";
|
||||
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
||||
import Keycloak from 'keycloak-js'
|
||||
import { AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO";
|
||||
@@ -27,7 +27,9 @@ export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
|
||||
newAdmin.email = keycloak.tokenParsed.email || "";
|
||||
newAdmin.nom = keycloak.tokenParsed.family_name || "";
|
||||
newAdmin.prenom = keycloak.tokenParsed.given_name || "";
|
||||
const response = await athleteService.create(newAdmin.toDTO());
|
||||
console.log(newAdmin.keycloakId);
|
||||
console.log(newAdmin.toDTO().id_keycloak);
|
||||
const response = await adminService.create(newAdmin.toDTO());
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
@@ -217,7 +219,7 @@ export async function postAthlete(athlete: Athlete):Promise<Athlete>{
|
||||
|
||||
export async function postSession(session: Session){
|
||||
try {
|
||||
const data = {
|
||||
/* const data = {
|
||||
name: session.name,
|
||||
creneau: session.creneau, // string ISO OK
|
||||
duree: session.duree,
|
||||
@@ -225,9 +227,9 @@ export async function postSession(session: Session){
|
||||
|
||||
coachId: session.coach?.id,
|
||||
groupe: session.groupe ? session.groupe : undefined,
|
||||
}
|
||||
}*/
|
||||
|
||||
const response = await sessionService.create(data);
|
||||
const response = await sessionService.create(session.toDTO());
|
||||
session.id = response.data.id; //TODO ?
|
||||
|
||||
session.activites.forEach(activite => {
|
||||
@@ -331,6 +333,44 @@ export async function getAllSessionsAPI():Promise<Session[]>{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function formatDateLocal(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
|
||||
export async function getAllSessionsBetweenAPI(d1:Date,d2:Date):Promise<Session[]>{
|
||||
try {
|
||||
const data = {
|
||||
startDate: formatDateLocal(d1),
|
||||
endDate: formatDateLocal(d2)
|
||||
}
|
||||
console.log(d1 + " " + d2);
|
||||
console.log(data);
|
||||
const response = await sessionService.getAllBetweenDate(data);
|
||||
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);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//COACH
|
||||
export async function getAllCoach(): Promise<Coach[]> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user