Blindage du test sur if (result.lentgth)
This commit is contained in:
14
app.js
14
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('/');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="mb-3">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Pour quelle occasion veux-tu l'offrir ?</label>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="occasion" id="occasion1" value="1" {{#if infosCadeaux.pourNoel}}checked{{/if}}>
|
||||
|
||||
Reference in New Issue
Block a user