mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 02:20:17 +01:00
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const validSources = ["borne", "website"];
|
|
const validSexes = ["h","f","a"];
|
|
|
|
export class Review {
|
|
constructor(auteur, note, source, commentaire=null, notesAutre={}) {
|
|
this.auteur = auteur;
|
|
this.note = note;
|
|
this.source = source;
|
|
this.commentaire = commentaire;
|
|
this.notesAutre = notesAutre;
|
|
//On vérifie si toutes les données sont correctes
|
|
if(note < 0 || note > 10) {
|
|
throw new Error("Note principale invalide");
|
|
}
|
|
for(let nom in notesAutre) {
|
|
if(notesAutre[nom] < 0 || notesAutre[nom] > 10) {
|
|
throw new Error("Note " + notesAutre[nom] +"/10 invalide");
|
|
}
|
|
}
|
|
if(!validSources.includes(source)) {
|
|
throw new Error("Source invalide");
|
|
}
|
|
if(!auteur instanceof Auteur) {
|
|
throw new Error("L'auteur est invalide");
|
|
}
|
|
}
|
|
}
|
|
|
|
export class Auteur {
|
|
constructor(age=null, sexe=null) {
|
|
this.age = age;
|
|
this.sexe = sexe;
|
|
|
|
if(sexe != undefined && !validSexes.includes(sexe) ) {
|
|
throw new Error("Sexe invalide");
|
|
}
|
|
if(age != undefined && age <= 0) {
|
|
throw new Error("Age invalide");
|
|
}
|
|
}
|
|
} |