Metzploreur/routes/posts.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-11-01 02:01:18 +00:00
const express = require('express');
const mongodb = require('mongodb')
const bcrypt = require('bcryptjs');
const db = require('../data/database');
const router = express.Router();
2023-11-01 20:03:07 +00:00
2023-11-01 02:01:18 +00:00
router.post('/creerPost', async function (req,res) {
const postData = req.body;
const enteredTitre = postData.titre;
const enteredCommentaire = postData.commentairePost;
2023-11-01 20:03:07 +00:00
const enterdRecompense = postData.recompense;
2023-11-01 02:01:18 +00:00
const post ={
titre: enteredTitre,
commentaire: enteredCommentaire,
2023-11-01 20:03:07 +00:00
recompense: enterdRecompense,
2023-11-01 02:01:18 +00:00
isFinish: false,
}
await db.getDb().collection('posts').insertOne(post);
2023-11-01 20:03:07 +00:00
return res.redirect('/admin');
2023-11-01 02:01:18 +00:00
})
2023-11-01 16:33:25 +00:00
router.get('/hotLine', async function (req,res) {
if (!req.session.isAuthenticated) {
return res.status(401).render('401');
}
const postData = await db.getDb().collection('posts').find().toArray();
2023-11-01 02:01:18 +00:00
res.render('hotLine', {postData: postData})
})
router.post('/commandeCrepe', async function (req, res) {
const crepeData = req.body;
const enteredCommentaire = crepeData.commentaire;
const enteredGarniture = crepeData.garniture;
const crepeCommande = {
garniture: enteredGarniture,
commentaire: enteredCommentaire,
finish: false
}
await db.getDb().collection('commande').insertOne(crepeCommande);
res.redirect("/hotLine");
})
2023-11-01 20:03:07 +00:00
router.post('/submitResolution/:postId', 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 resolution = {
description: enteredDescription,
nom: nom,
prenom: prenom,
}
return res.redirect('/hotLine');
});
2023-11-01 02:01:18 +00:00
module.exports = router;