back-end hotline finish

This commit is contained in:
clement callaert 2023-11-02 00:03:46 +01:00
parent 6676f0834b
commit 5b289819d7
5 changed files with 57 additions and 15 deletions

View file

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

View file

@ -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});
})

View file

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

View file

@ -64,6 +64,41 @@
<button>Submit</button>
</form>
</li>
<li>
<h2>Les postes</h2>
<% postData.forEach(post => { %>
<% if (post.isFinish) {%>
<div id="postFinish">
<h2><%= post.titre %></h2>
<p>
<%= post.commentairePost %>
</p>
<p>
Récompense : <%= post.recompense %>
</p>
<p>
statue : Accepté
</p>
</div>
<% } else {%>
<div id="postNotFinish">
<h2><%= post.titre %></h2>
<p>
Déscription : <%= post.commentaire %>
</p>
<p>
Récompense : <%= post.recompense %>
</p>
<p>
statue : en attente
</p>
<button id="but<%= post._id %>" data-post-id="<%= post._id %>">
Soummettre sa resolution
</button>
</div>
<% } %>
<% }); %>
</li>
</ul>
</div>
</main>

View file

@ -12,10 +12,10 @@
<h1>
soumettre sa résolution
</h1>
<form>
<form method="post" enctype="multipart/form-data">
<div>
<label for="">Mettre l'image : </label>
<input type="file" id="image" name="image" required>
<label for="image">Mettre l'image : </label>
<input type="file" id="image" name="image">
</div>
<div>
<label for="description">Ajouter une description</label>