Nouvelle version, simplifiée
This commit is contained in:
62
wishlist.js
62
wishlist.js
@@ -6,6 +6,10 @@ const path = require("path")
|
||||
const publicDir = path.join(__dirname, './public')
|
||||
var bodyParser = require('body-parser')
|
||||
|
||||
/* Pour le Javascript embarqué */
|
||||
app.use('/js', express.static(__dirname + './../public'));
|
||||
|
||||
|
||||
/* Connexion à la BDD MySQL */
|
||||
dotenv.config({ path: './.env'})
|
||||
const db = mysql.createConnection({
|
||||
@@ -23,7 +27,6 @@ db.connect((error) => {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
app.set('view engine', 'hbs');
|
||||
app.use(express.static(publicDir));
|
||||
/* Pour utiliser le bootstrap local */
|
||||
@@ -48,7 +51,7 @@ hbs.registerHelper('equals', isEqual);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
|
||||
db.query('SELECT c.id as "id", c.libelle as "libelle", c.prix, c.photo as "photo", c.lien, p.prenom as "acheteur", c.achete as "achete", c.paye as "paye", p2.prenom as "responsableAchat", c.pour_noel as "pourNoel", c.emballe as "emballe" FROM cadeau c LEFT OUTER JOIN participations pc on pc.cadeau = c.id LEFT OUTER JOIN participant p on p.id = pc.offrant LEFT OUTER JOIN participant p2 on p2.id = pc.responsable_achat ORDER BY c.pour_noel, c.prix', async (error, resultCadeaux) => {
|
||||
db.query('SELECT c.id as "id", c.libelle as "libelle", c.prix, c.photo as "photo", c.lien, pc.offrant as "acheteur", c.pour_noel as "pourNoel" FROM cadeau c LEFT OUTER JOIN participations pc on pc.cadeau = c.id ORDER BY c.pour_noel, c.prix', async (error, resultCadeaux) => {
|
||||
let message;
|
||||
|
||||
if(error){
|
||||
@@ -66,70 +69,35 @@ app.get("/", (req, res) => {
|
||||
app.get("/choix-offrant", (req, res) => {
|
||||
let cadeau = req.query.cadeau;
|
||||
|
||||
db.query('SELECT id, prenom FROM participant ORDER BY prenom', async (error, result) => {
|
||||
if(error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (result && result.length > 0) {
|
||||
res.render('offrant', { "cadeau" : cadeau, "listeOffrants": result});
|
||||
}
|
||||
})
|
||||
res.render('offrant', { "cadeau" : cadeau});
|
||||
})
|
||||
|
||||
|
||||
app.get("/reservation", (req, res) => {
|
||||
|
||||
let reqCadeau = req.query.cadeau;
|
||||
let reqOffrant = req.query.offrant;
|
||||
let totalAchats;
|
||||
let cadeau = req.query.cadeau;
|
||||
let offrant = req.query.offrant;
|
||||
|
||||
db.query('SELECT id, libelle, prix, photo, lien, achete, paye, pour_noel as "pourNoel" FROM cadeau WHERE id = ?', [reqCadeau], async (error, infosCadeau) => {
|
||||
db.query('SELECT id, libelle, prix, photo, lien, pour_noel as "pourNoel" FROM cadeau WHERE id = ?', [cadeau], async (error, infosCadeau) => {
|
||||
if(error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (infosCadeau.length > 0) {
|
||||
db.query('SELECT COALESCE(sum(c.prix),0) as "total" FROM cadeau c RIGHT OUTER JOIN participations pc ON pc.cadeau = c.id INNER JOIN participant p ON p.id = pc.offrant WHERE p.id=?', [reqOffrant], async (error, result) => {
|
||||
if(error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (result && result.length > 0) {
|
||||
totalAchats = result[0]
|
||||
}
|
||||
res.render('reservation', { "infosCadeau": infosCadeau[0], "offrant" : offrant });
|
||||
});
|
||||
|
||||
db.query('SELECT id, prenom FROM participant WHERE id=?', [reqOffrant], async (error, result) => {
|
||||
if(error) {
|
||||
console.log(error);
|
||||
}
|
||||
if (result && result.length > 0) {
|
||||
offrant = result[0];
|
||||
}
|
||||
});
|
||||
|
||||
db.query('SELECT id, prenom FROM participant ORDER BY prenom', async (error, listeResponsables) => {
|
||||
if(error) {
|
||||
console.log(error);
|
||||
}
|
||||
res.render('reservation', { "infosCadeaux": infosCadeau[0],
|
||||
"offrant" : offrant,
|
||||
"totalAchats": totalAchats.total,
|
||||
"listeResponsables" : listeResponsables} );
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.post("/confirm-reservation", (req, res) => {
|
||||
const { cadeau, offrant, achete, paye, occasion, responsableAchat } = req.body
|
||||
const { cadeau, offrant, occasion } = req.body
|
||||
|
||||
db.query('UPDATE cadeau SET achete=?, paye=?, pour_noel=? WHERE ID=?', [achete, paye, occasion, cadeau], function (err, result) {
|
||||
db.query('UPDATE cadeau SET pour_noel=? WHERE ID=?', [occasion, cadeau], function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("1 record updated");
|
||||
});
|
||||
|
||||
db.query('INSERT INTO participations (offrant, cadeau, responsable_achat) VALUES (?, ?, ?)', [offrant, cadeau, responsableAchat], function (err, result) {
|
||||
db.query('INSERT INTO participations (offrant, cadeau) VALUES (?, ?)', [offrant, cadeau], function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("1 record inserted");
|
||||
});
|
||||
@@ -143,7 +111,7 @@ app.get("/presence-anniversaire", (req, res) => {
|
||||
var child_process = require("child_process");
|
||||
let enfant = req.query.e;
|
||||
let present = req.query.p;
|
||||
let messageNotif = enfant + (present == 'true' ? "" : " ne") + " sera" + (present == 'true' ? "" : " pas") + " là le 17 décembre";
|
||||
let messageNotif = enfant + (present == 'true' ? "" : " ne") + " sera" + (present == 'true' ? "" : " pas") + " là le 14 décembre 2024";
|
||||
|
||||
db.query("DELETE FROM anniversaire WHERE enfant = ?", [enfant], function (err, result) {
|
||||
if (err) throw err;
|
||||
|
||||
Reference in New Issue
Block a user