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 @@