diff --git a/routes/auth.js b/routes/auth.js index 02081ce..539813b 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -61,7 +61,8 @@ router.post('/creer-compte', async function (req, res) { return; } - const existingUser = await db.getDb().collection('users').findOne({email: enteredEmail}); + const existingUser = await db.getDb().collection('users').findOne({email: enteredEmail}) || + db.getDb().collection('users').findOne({nom_dutilisateur: enteredNom_dutilisateur}); if (existingUser) { req.session.inputData = { @@ -176,5 +177,4 @@ router.post('/supprAdmin', async function (req,res) { await db.getDb().collection('users').updateOne({nom_dutilisateur: enteredNomDutilisateur}, {$set: {isAdmin: false}}) }) - module.exports = router \ No newline at end of file diff --git a/routes/demo.js b/routes/demo.js index 55431b0..70b9ee6 100644 --- a/routes/demo.js +++ b/routes/demo.js @@ -28,7 +28,9 @@ router.get('/admin', async function (req, res) { } const users = await db.getDb().collection('users').find().toArray(); - res.render('adminPage', {users: users}); + 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}); }) diff --git a/routes/posts.js b/routes/posts.js index 79ed5e6..e9789bc 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -59,7 +59,7 @@ router.post('/commandeCrepe', async function (req, res) { }) router.post('/submitResolution/:postId', upload.single('image'), async function (req, res) { - const postId = req.params.postId; + const postId = req.params.postId; // Assuming postId is obtained from the request const resolutionData = req.body; const enteredDescription = resolutionData.description; const user = req.session.user; @@ -69,15 +69,20 @@ router.post('/submitResolution/:postId', upload.single('image'), async function const path = file.path; const resolution = { - description: enteredDescription, - nom: nom, - prenom: prenom, - imagePath: path - } + postId: postId, + description: enteredDescription, + nom: nom, + prenom: prenom, + imagePath: path + } - await db.getDb().collection('posts').updateOne() + const filter = {id: postId}; + const updateDoc = { + $set: {[`resolutions.${postId}`]: resolution} + }; - return res.redirect('/hotLine'); -}); + const result = await db.getDb().collection('res').insertOne(resolution); + return res.redirect('/hotLine') +}) module.exports = router; \ No newline at end of file diff --git a/views/adminPage.ejs b/views/adminPage.ejs index bda3645..2ad0bac 100644 --- a/views/adminPage.ejs +++ b/views/adminPage.ejs @@ -64,6 +64,41 @@ +
  • +

    Les postes

    + <% postData.forEach(post => { %> + <% if (post.isFinish) {%> +
    +

    <%= post.titre %>

    +

    + <%= post.commentairePost %> +

    +

    + Récompense : <%= post.recompense %> +

    +

    + statue : Accepté +

    +
    + <% } else {%> +
    +

    <%= post.titre %>

    +

    + Déscription : <%= post.commentaire %> +

    +

    + Récompense : <%= post.recompense %> +

    +

    + statue : en attente +

    + +
    + <% } %> + <% }); %> +
  • diff --git a/views/hotLine.ejs b/views/hotLine.ejs index 0c80404..0fb9c6a 100644 --- a/views/hotLine.ejs +++ b/views/hotLine.ejs @@ -12,10 +12,10 @@

    soumettre sa résolution

    -
    +
    - - + +