mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 10:30:17 +01:00
ajout insertion d'avis et auteurs
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user