mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-10 02:50:17 +01:00
ajout des structures de données + connexion BDD
This commit is contained in:
41
code/server/structures.js
Normal file
41
code/server/structures.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user