contructeur classes, type DTO dans TS, clean hard code

This commit is contained in:
trochas
2026-01-08 15:42:11 +01:00
parent 78b82fcfee
commit f2a0f8ca86
7 changed files with 207 additions and 97 deletions

View File

@@ -1,15 +1,7 @@
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
export type Role = "admin" | "athlete" | "coach";
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO";
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
export class User{
id!: number;
keycloakId!: String;
nom!: string;
prenom!:string;
sessions: Session[] = []; //nb: Admin liaison non symétrique /!\
email!: string;
role!: Role;
}
export class Ligne{
id!: number;
@@ -18,32 +10,103 @@ export class Ligne{
tempsDeJeu!: number; // en minutes
}
export class User{
id!: number;
keycloakId!: String;
nom!: string;
prenom!:string;
email!: string;
}
export class Admin extends User{
role!: Role;
constructor(dto:AdminDTO);
constructor();
constructor(dto?:AdminDTO){
super();
this.id = dto?.id ?? 0;
this.keycloakId = dto?.id_keycloak ?? "";
this.nom = dto?.name ?? "";
this.prenom = dto?.prenom ?? "";
this.email = ""; //TODO
}
}
export class Athlete extends User{
nom!: string;
groupe!: Groupe;
role!: Role;
groupes!: Groupe[];
sessionsID!: number[];
sessions: Session[] = [];
constructor(dto:AthleteDTO);
constructor();
constructor(dto?:AthleteDTO){
super();
this.id = dto?.id ?? 0;
this.keycloakId = dto?.id_keycloak ?? "";
this.nom = dto?.name ?? "";
this.prenom = dto?.prenom ?? "" ;
this.email = ""; //TODO
this.groupes = dto?.groupes ?? [];
this.sessionsID = dto?.sessionIds ?? [];
this.sessions = [];
}
}
export class Coach extends User{
nom!: string;
role!: Role;
sessionsID!: number[];
sessions: Session[] = [];
constructor(dto:CoachDTO);
constructor();
constructor(dto?:CoachDTO){
super();
this.id = dto?.id ?? 0;
this.keycloakId = dto?.id_keycloak ?? "";
this.nom = dto?.name ?? "";
this.prenom = dto?.prenom ?? "";
this.email = ""; //TODO
this.sessionsID = dto?.sessionIds ?? [];
this.sessions = [];
}
}
export class Session{
id!: number;
name!: string;
activitesID: number[] = [];
activites: Activite[] = [];
isRecurrent! : Boolean;
creneau!: Date;
coach!: Coach;
athletesID!: number[]
athletes!: Athlete[]
duree! : number;
groupe! : Groupe;
ligne! : Ligne[];
constructor(dto:SessionDTO);
constructor();
constructor(dto?:SessionDTO){
this.id = dto?.id?? 0;
this.name = dto?.name?? "";
this.activitesID = dto?.activiteIds?? [];
this.activites = [];
this.isRecurrent = dto?.isRecurrent?? false;
this.creneau = dto? new Date(dto.creneau) : new Date();
//this.coach = new Coach(); //dto.coachId; //TODO
this.athletesID = dto?.athleteIds ?? [];
this.athletes = [];
this.duree = dto?.duree ?? 0;
this.groupe = dto?.groupe ?? "";
this.ligne = []; //TODO
}
}
export class Activite{
@@ -54,10 +117,23 @@ export class Activite{
data!: Map<string,string>;
duree!: number;
}
constructor(dto:ActiviteDTO);
constructor();
constructor(dto?:ActiviteDTO){
this.id = dto?.id ?? 0;
this.nom = dto?.name ?? "";
//this.session = dto.sessionId; //TODO
this.theme = dto?.theme ?? "";
//this.data = //TODO
this.duree = dto?.duree ?? 0;
}
}
/*
export function getUserTest():User{
const user = new User();
const user = new Athlete();
const s1 = new Session();
const s2 = new Session();
const s3 = new Session();
@@ -65,17 +141,17 @@ export function getUserTest():User{
athlete1.id = 1;
athlete1.nom = "Alice Dupont";
athlete1.email = "alice@nootnoot.yee";
athlete1.groupe = "Entrainement";
athlete1.groupes = ["Entrainement"];
const athlete2 = new Athlete();
athlete2.id = 2;
athlete2.nom = "Bob Martin";
athlete2.groupe = "Competition";
athlete2.groupes = ["Competition"];
const athlete3 = new Athlete();
athlete3.id = 3;
athlete3.nom = "Clara Lopez";
athlete3.groupe = "Loisir";
athlete3.groupes = ["Loisir"];
const ligne1 = new Ligne();
ligne1.id = 1;
@@ -99,7 +175,6 @@ export function getUserTest():User{
user.id = 0;
user.nom = "Emilien-Yee NootNoot";
user.role = "coach"
user.email = "emilien@nootnoot.yee";
s1.creneau = new Date();
s1.id = 1;
@@ -187,9 +262,7 @@ export function getUserTest():User{
user.sessions.push(s2);
user.sessions.push(s3);
athlete1.role = "athlete";
athlete2.role = "athlete";
athlete3.role = "athlete";
return user;
}
*/