diff --git a/app.js b/app.js index c402768..2a30ba9 100644 --- a/app.js +++ b/app.js @@ -42,7 +42,7 @@ app.get("/", (req, res) => { if(error){ console.log(error); } - if (resultCadeaux.length == 0) { + if (resultCadeaux && resultCadeaux.length == 0) { console.log("Aucun cadeau"); message = "Aucun cadeau pour l'instant"; } @@ -58,7 +58,7 @@ app.get("/choix-offrant", (req, res) => { if(error) { console.log(error); } - if (result.length > 0) { + if (result && result.length > 0) { res.render('offrant', { "cadeau" : cadeau, "listeOffrants": result}); } }) @@ -69,7 +69,6 @@ app.get("/reservation", (req, res) => { let reqCadeau = req.query.cadeau; let reqOffrant = req.query.offrant; - let totalAchats; db.query('SELECT id, libelle, prix, photo, lien, achete, paye, pour_noel as "pourNoel" FROM cadeau WHERE id = ?', [reqCadeau], async (error, infosCadeau) => { @@ -81,7 +80,7 @@ app.get("/reservation", (req, res) => { if(error) { console.log(error); } - if (result.length > 0) { + if (result && result.length > 0) { totalAchats = result[0] } @@ -89,7 +88,7 @@ app.get("/reservation", (req, res) => { if(error) { console.log(error); } - if (result.length > 0) { + if (result && result.length > 0) { offrant = result[0]; } }); @@ -111,7 +110,6 @@ app.get("/reservation", (req, res) => { app.post("/confirm-reservation", (req, res) => { - const { cadeau, offrant, achete, paye, occasion, responsableAchat } = req.body db.query('UPDATE cadeau SET achete=?, paye=?, pour_noel=? WHERE ID=?', [achete, paye, occasion, cadeau], function (err, result) { @@ -121,12 +119,10 @@ app.post("/confirm-reservation", (req, res) => { db.query('INSERT INTO participations (offrant, cadeau, responsable_achat) VALUES (?, ?, ?)', [offrant, cadeau, responsableAchat], function (err, result) { if (err) throw err; - console.log("1 record updated"); + console.log("1 record inserted"); }); - res.redirect('/'); - }); diff --git a/views/reservation.hbs b/views/reservation.hbs index 8ec881b..8cb81d8 100644 --- a/views/reservation.hbs +++ b/views/reservation.hbs @@ -64,7 +64,7 @@
-
+