diff --git a/routes/auth.js b/routes/auth.js index 13ff679..e51283f 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -172,14 +172,16 @@ router.post('/logout', function (req, res) { res.redirect('/'); }); -router.post('mettreAdmin', async function (req,res) { - const enteredNomDutilisateur = res.body.utilisateurs; +router.post('/mettreAdmin', async function (req,res) { + const enteredNomDutilisateur = req.body.utilisateurs; await db.getDb().collection('users').updateOne({nom_dutilisateur: enteredNomDutilisateur}, {$set: {isAdmin: true}}) + return res.redirect('/admin') }) router.post('/supprAdmin', async function (req,res) { - const enteredNomDutilisateur = res.body.utilisateurs; + const enteredNomDutilisateur = req.body.utilisateurs; await db.getDb().collection('users').updateOne({nom_dutilisateur: enteredNomDutilisateur}, {$set: {isAdmin: false}}) + return res.redirect('/admin') }) module.exports = router \ No newline at end of file diff --git a/routes/demo.js b/routes/demo.js index a54cd51..2bf5353 100644 --- a/routes/demo.js +++ b/routes/demo.js @@ -30,7 +30,8 @@ router.get('/admin', async function (req, res) { const users = await db.getDb().collection('users').find().toArray(); const postData = await db.getDb().collection('posts').find().toArray(); const resData = await db.getDb().collection('res').find().toArray(); - res.render('adminPage', {users: users, postData: postData, resData:resData}); + const commandeData = await db.getDb().collection('commandes').find().toArray(); + res.render('adminPage', {users: users, postData: postData, resData:resData, commandeData: commandeData}); }) diff --git a/routes/posts.js b/routes/posts.js index 836a078..c123501 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -111,5 +111,12 @@ router.post('/supprimerPost/:id', async function (req, res) { return res.redirect('/admin'); }); +router.post('/isFinish/:id', async function (req, res) { + const postId = req.params.id; + const ObjectID = mongodb.ObjectId; + const postObjectId = new ObjectID(postId); + await db.getDb().collection('commandes').updateOne({ _id: postObjectId }, {$set: {isFinish: true}}); + return res.redirect('/admin'); +}) module.exports = router; \ No newline at end of file diff --git a/views/adminPage.ejs b/views/adminPage.ejs index b8aa497..4a1752d 100644 --- a/views/adminPage.ejs +++ b/views/adminPage.ejs @@ -14,7 +14,7 @@

Faire de quelqu'un un admin

-
+ <% users.forEach(user => { %> @@ -42,6 +42,32 @@
+
  • +

    + Commandes +

    + <% if (commandeData.length === 0) {%> +

    + Pas encore de commande +

    + <% } %> + <% commandeData.forEach(commande => { %> + <% if (!commande.isFinish) { %> +

    + <%= commande.nom %> <%= commande.prenom %> +

    +

    + <%= commande.commentaire %> + <%= commande.garniture %> +

    +
    + +
    + <% } %> + <% }) %> +
  • Créer un poste pour la hotLine diff --git a/views/hotLine.ejs b/views/hotLine.ejs index 41a69d6..8857449 100644 --- a/views/hotLine.ejs +++ b/views/hotLine.ejs @@ -41,6 +41,7 @@ nutella confiture + sucre

  • @@ -54,13 +55,10 @@

    Commandes

    - <% if (commandeData.length === 0) {%> -

    - Pas encore de commande -

    - <% } %> + <% let toutesLesCommandesSontTerminees = true; %> <% commandeData.forEach(commande => { %> <% if (!commande.isFinish) { %> + <% toutesLesCommandesSontTerminees = false; %>

    <%= commande.nom %> <%= commande.prenom %>

    @@ -70,6 +68,12 @@

    <% } %> <% }) %> + <% if (toutesLesCommandesSontTerminees) { %> +

    + Pas encore de commande +

    + <% } %> +

    @@ -89,7 +93,7 @@ Récompense : <%= post.recompense %>

    - statue : Accepté + statut : Accepté

    <% } else {%> @@ -102,7 +106,7 @@ Récompense : <%= post.recompense %>

    - statue : en attente + statut : en attente