From 6676f0834bfc5f0695a1921535f23c4bdb231aae Mon Sep 17 00:00:00 2001 From: clement callaert Date: Wed, 1 Nov 2023 22:50:28 +0100 Subject: [PATCH] hotline modified --- routes/posts.js | 24 +++++++++++++++++++++--- views/hotLine.ejs | 11 ++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/routes/posts.js b/routes/posts.js index 3bf8613..79ed5e6 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -1,17 +1,31 @@ const express = require('express'); const mongodb = require('mongodb') const bcrypt = require('bcryptjs'); +const multer = require('multer') + +const storageConfig = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, 'images'); + }, + filename: function (req, file, cb) { + cb(null, Date.now() + '-' + file.originalname); + } +}); + +const upload = multer({storage: storageConfig}); const db = require('../data/database'); const router = express.Router(); -router.post('/creerPost', async function (req,res) { +router.post('/creerPost', async function (req,res) { const postData = req.body; const enteredTitre = postData.titre; const enteredCommentaire = postData.commentairePost; const enterdRecompense = postData.recompense; + + const post ={ titre: enteredTitre, commentaire: enteredCommentaire, @@ -44,21 +58,25 @@ router.post('/commandeCrepe', async function (req, res) { res.redirect("/hotLine"); }) -router.post('/submitResolution/:postId', async function (req, res) { +router.post('/submitResolution/:postId', upload.single('image'), async function (req, res) { const postId = req.params.postId; const resolutionData = req.body; const enteredDescription = resolutionData.description; const user = req.session.user; const nom = user.nom; const prenom = user.prenom; + const file = req.file; + const path = file.path; const resolution = { description: enteredDescription, nom: nom, prenom: prenom, - + imagePath: path } + await db.getDb().collection('posts').updateOne() + return res.redirect('/hotLine'); }); diff --git a/views/hotLine.ejs b/views/hotLine.ejs index a5b5971..0c80404 100644 --- a/views/hotLine.ejs +++ b/views/hotLine.ejs @@ -12,10 +12,15 @@

soumettre sa résolution

-

- test -

+
+ + +
+
+ + +