From e91293087602284c5aadbbd67c8c76204f11fca3 Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Sun, 19 Mar 2023 12:49:15 +0100 Subject: [PATCH] LAST COMMIT I HOPE --- src/class/api-service.js | 4 +--- src/view/nav-bar.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/class/api-service.js b/src/class/api-service.js index eb0e402..baf367a 100644 --- a/src/class/api-service.js +++ b/src/class/api-service.js @@ -17,9 +17,7 @@ class ApiService{ 'Accept': 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify({ - word:"yessss" - }) + body: JSON.stringify(value) }; fetch(baseUrl, headers).then( (response) => { if (response.ok) diff --git a/src/view/nav-bar.js b/src/view/nav-bar.js index fdd3189..c9728db 100644 --- a/src/view/nav-bar.js +++ b/src/view/nav-bar.js @@ -121,21 +121,33 @@ export default{ const equipe1 = document.querySelector("#equipe1").value const equipe2 = document.querySelector("#equipe2").value - const equipe1Score = document.querySelector("#equipe1Score").value - const equipe2Score = document.querySelector("#equipe2Score").value + const stringEquipe1Score = document.querySelector("#equipe1Score").value + const stringEquipe2Score = document.querySelector("#equipe2Score").value + + const equipe1Score = parseInt(stringEquipe1Score); + const equipe2Score = parseInt(stringEquipe2Score); + const res = this.teams.filter(item => item.name === equipe1) + + const res2 = this.teams.filter(item => item.name === equipe2) + + console.log(res) + console.log(res2) + + let tab = [res,res2] if (equipe1Score=="" || equipe2Score=="") { this.errMessageMatch="Veuillez rentrer le score de TOUTES les equipes"; return; } - - - const JSON = `[{"name":${equipe1},"score":${equipe1Score}},{"name":${equipe2},"score":${equipe2Score}}]` + if (equipe1Score < 0 || equipe2Score < 0) { + this.errMessageMatch = "Veuilez rentre un score positif"; + return + } try { const api = ApiService(); - api.post("http://www.post-result.com",JSON) + api.post("http://www.post-result.com",tab) } catch (Error) { this.errMessageMatch="Une erreur sur la requette POST" }