ajout insertion d'avis et auteurs

This commit is contained in:
2022-12-24 15:07:25 +01:00
parent 9da7b5f675
commit f748cfb95f
5 changed files with 259 additions and 169 deletions

View File

@@ -2,32 +2,32 @@ const validSources = ["borne", "website"];
const validSexes = ["h","f"];
export class Review {
constructor(author, mainRating, source, message="", otherRatings={}) {
this.author = author;
this.mainRating = mainRating;
constructor(auteur, note, source, commentaire=null, notesAutre={}) {
this.auteur = auteur;
this.note = note;
this.source = source;
this.message = message;
this.otherRatings = otherRatings;
this.commentaire = commentaire;
this.notesAutre = notesAutre;
//On vérifie si toutes les données sont correctes
if(mainRating < 0 || mainRating > 10) {
if(note < 0 || note > 10) {
throw new Error("Note principale invalide");
}
for(rating of otherRatings) {
if(rating < 0 || rating > 10) {
for(let nom in notesAutre) {
if(notesAutre[nom] < 0 || notesAutre[nom] > 10) {
throw new Error("Note " + rating +"/10 invalide");
}
}
if(!validSources.includes(source)) {
throw new Error("Source invalide");
}
if(!author instanceof Auteur) {
if(!auteur instanceof Auteur) {
throw new Error("L'auteur est invalide");
}
}
}
export class Auteur {
constructor(age=undefined, sexe=undefined) {
constructor(age=null, sexe=null) {
this.age = age;
this.sexe = sexe;