contructeur classes, type DTO dans TS, clean hard code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import api, { activiteService, sessionService } from "./api";
|
||||
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
||||
import Keycloak from 'keycloak-js'
|
||||
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||
|
||||
//debug:
|
||||
export function delay(ms: number): Promise<void> {
|
||||
@@ -19,16 +20,19 @@ export async function getUser(keycloak:Keycloak): Promise<User|null>{
|
||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||
if(roles!=null){
|
||||
if(roles.includes("admin")){
|
||||
const response = await api.get<any>(`/TODO`);
|
||||
return response.data;
|
||||
const response = await api.get<AdminDTO>(`/TODO`);
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
else if(roles.includes("coach")){
|
||||
const response = await api.get<any>(`/TODO`);
|
||||
return response.data;
|
||||
const response = await api.get<CoachDTO>(`/TODO`);
|
||||
const coach = new Coach(response.data);
|
||||
return coach;
|
||||
}
|
||||
else if(roles.includes("athletes")){
|
||||
const response = await api.get<any>(`/TODO`);
|
||||
return response.data;
|
||||
const response = await api.get<AthleteDTO>(`/TODO`);
|
||||
const athlete = new Athlete(response.data);
|
||||
return athlete;
|
||||
}
|
||||
console.error("Error roles inconnu");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user