Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/hackathon
This commit is contained in:
@@ -19,23 +19,23 @@ retourne l'utilisateur lié à l'identifiant keyloack
|
||||
export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
|
||||
try {
|
||||
if(keycloak.tokenParsed!=null){
|
||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||
if(roles!=null){
|
||||
if(roles.includes("admin")){
|
||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||
if(roles!=null){
|
||||
if(roles.includes("admin")){
|
||||
const id = keycloak.tokenParsed?.sub;
|
||||
if(id!=null){
|
||||
const response = await athleteService.getByKeycloakId(id);
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
}
|
||||
else if(roles.includes("coach")){
|
||||
else if(roles.includes("coach")){
|
||||
const id = keycloak.tokenParsed?.sub;
|
||||
if(id!=null){
|
||||
const response = await coachService.getByKeycloakId(id);
|
||||
const coach = new Coach(response.data);
|
||||
return coach;
|
||||
}
|
||||
const coach = new Coach(response.data);
|
||||
return coach;
|
||||
}
|
||||
}
|
||||
else if(roles.includes("athlete")){
|
||||
console.error("role = Athlete");
|
||||
@@ -46,10 +46,10 @@ export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
|
||||
newAthlete.prenom = keycloak.tokenParsed.given_name || "";
|
||||
const response = await athleteService.create(newAthlete.toDTO());
|
||||
console.log(response);
|
||||
const athlete = new Athlete(response.data);
|
||||
const athlete = new Athlete(response.data);
|
||||
console.log(athlete);
|
||||
return athlete;
|
||||
}
|
||||
return athlete;
|
||||
}
|
||||
else console.error("Error : role inconnu");
|
||||
}
|
||||
else console.error("Error : role null");
|
||||
@@ -64,9 +64,21 @@ export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateActivitiesOfSessionAPI(session:Session){
|
||||
export async function updateActivitiesOfSessionAPI(session:Session,activities:Activite[]){
|
||||
try {
|
||||
const response = await api.get<Activite[]>(`/sessions/${session.id}/activities`);
|
||||
const session_id = session.id
|
||||
for (const activity of activities) {
|
||||
const response = await activiteService.update(activity.id!, {
|
||||
name: activity.nom,
|
||||
duree: activity.duree,
|
||||
date: activity.data,
|
||||
theme: activity.theme,
|
||||
sessionId: session_id,
|
||||
},
|
||||
);
|
||||
}
|
||||
// To refresh the activities in the session object
|
||||
const response = await sessionService.getActivities(session_id!);
|
||||
session.activites = response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching activities for session:", error);
|
||||
@@ -76,7 +88,9 @@ export async function updateActivitiesOfSessionAPI(session:Session){
|
||||
|
||||
export async function subscribeSessionAPI(user:User, session:Session):Promise<boolean>{
|
||||
try {
|
||||
await api.post(`/sessions/${session.id}/subscribe`);
|
||||
const session_id =session.id
|
||||
const user_id = user.id
|
||||
const response = await sessionService.subscribe(session_id!, user_id!);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error subscribing to session:", error);
|
||||
@@ -86,7 +100,9 @@ export async function subscribeSessionAPI(user:User, session:Session):Promise<bo
|
||||
|
||||
export async function unsubscribeSessionAPI(user:User, session:Session):Promise<boolean>{
|
||||
try {
|
||||
await api.post(`/session/${session.id}/unsubscribe`);
|
||||
const session_id =session.id
|
||||
const user_id = user.id
|
||||
const response = await sessionService.unsubscribe(session_id!, user_id!);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error unsubscribing from session:", error);
|
||||
@@ -209,6 +225,16 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllSessionsAPI():Promise<Session[]>{
|
||||
try {
|
||||
const response = await sessionService.getAll();
|
||||
return response.data;
|
||||
} 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