diff --git a/main.js b/main.js index 111715c..f283c6e 100644 --- a/main.js +++ b/main.js @@ -26,6 +26,8 @@ app.use(authMiddleware); app.use(demoRoutes); app.use(authRoutes); app.use(postsRoutes); +app.use('/images', express.static(path.join(__dirname, 'images'))); + app.use(function(error, req, res, next) { res.render('500'); diff --git a/routes/posts.js b/routes/posts.js index a9e71dc..605a251 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -82,24 +82,32 @@ router.post('/submitResolution/:postId', upload.single('image'), async function prenom: prenom, imagePath: path } - - const filter = {id: postId}; - const updateDoc = { - $set: {[`resolutions.${postId}`]: resolution} - }; - const result = await db.getDb().collection('res').insertOne(resolution); return res.redirect('/hotLine') }) -router.post('/accepter/:id', async function (req, res) { +router.post('/accepterPost/:id', async function (req, res) { const postId = req.params.id; const winner = req.body.utilisateur; - await db.getDb().collection('post').updateOne({_id: postId}, {isFinish: true}); - await db.getDb().collection('res').updateOne({_id: postId}, {winner: winner}); - res.redirect('/admin') -}) + const ObjectID = mongodb.ObjectId; + const postObjectId = new ObjectID(postId); + + await db.getDb().collection('posts').updateOne({ _id: postObjectId }, { $set: { isFinish: true, winner: winner } }); + + await db.getDb().collection('res').updateOne({ _id: postObjectId }, { $set: { winner: winner } }); + + return res.redirect('/admin'); +}); + + +router.post('/supprimerPost/:id', async function (req, res) { + const postId = req.params.id; + const ObjectID = mongodb.ObjectId; + const postObjectId = new ObjectID(postId); + await db.getDb().collection('posts').deleteOne({ _id: postObjectId }); + return res.redirect('/admin'); +}); module.exports = router; \ No newline at end of file diff --git a/views/adminPage.ejs b/views/adminPage.ejs index cba6ec5..1505613 100644 --- a/views/adminPage.ejs +++ b/views/adminPage.ejs @@ -79,6 +79,14 @@

statue : Accepté

+

+ gagnant : <%= post.winner %> +

+
+ +
<% } else {%>
@@ -92,7 +100,7 @@

statue : en attente

-
+
-
+
+ +
<% } %> <% resData.forEach(res => {%> @@ -119,7 +132,7 @@

<%= res.description %>

- image de la resolution + image de la resolution <% } %> <% }) %> diff --git a/views/includes/header.ejs b/views/includes/header.ejs index 41e35dd..185e003 100644 --- a/views/includes/header.ejs +++ b/views/includes/header.ejs @@ -4,9 +4,11 @@ diff --git a/views/index.ejs b/views/index.ejs index 209aa0c..0c254a1 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -9,8 +9,12 @@
+ logo BDE permanent + + logo BDS +
@@ -41,8 +45,10 @@ }); -
- logo Metzploreur + <%- include('includes/footer') %>