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"];
|
|
|
|
export class Review {
|
|
constructor(author, mainRating, source, message="", otherRatings={}) {
|
|
this.author = author;
|
|
this.mainRating = mainRating;
|
|
this.source = source;
|
|
this.message = message;
|
|
this.otherRatings = otherRatings;
|
|
//On vérifie si toutes les données sont correctes
|
|
if(mainRating < 0 || mainRating > 10) {
|
|
throw new Error("Note principale invalide");
|
|
}
|
|
for(rating of otherRatings) {
|
|
if(rating < 0 || rating > 10) {
|
|
throw new Error("Note " + rating +"/10 invalide");
|
|
}
|
|
}
|
|
if(!validSources.includes(source)) {
|
|
throw new Error("Source invalide");
|
|
}
|
|
if(!author instanceof Auteur) {
|
|
throw new Error("L'auteur est invalide");
|
|
}
|
|
}
|
|
}
|
|
|
|
export class Auteur {
|
|
constructor(age=undefined, sexe=undefined) {
|
|
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");
|
|
}
|
|
}
|
|
} |