Skip to content
Snippets Groups Projects
Commit bbc727f0 authored by Mamadu-lamarana Bah's avatar Mamadu-lamarana Bah :speech_balloon:
Browse files

tickets reservation

parent 5287344d
No related branches found
No related tags found
No related merge requests found
......@@ -44,22 +44,25 @@ const displayList = async () => {
const addToList = (show,list) => {
const node = document.createElement('div');
node.id = show._id;
node.textContent = `${show.description} (${show.places})`;
const span = document.createElement('span');
span.className = "places";
span.textContent = `${show.places} places`
node.textContent = `${show.description} : `;
node.appendChild(span);
//
//node.addEventListener('mouseover', () => getTask(show._id));
//
const ticketsButton = document.createElement('button');
ticketsButton.className = 'ticket';
ticketsButton.addEventListener('click', ajoutTicketShow);
ticketsButton.addEventListener('click', addTicketShow);
ticketsButton.textContent = '+1 tickets';
node.appendChild(ticketsButton);
//
list.appendChild(node);
}
const update = async () => {
const userData = { name : username.value };
const body = JSON.stringify(userData);
const update = async (data) => {
const body = JSON.stringify(data);
const requestOptions = {
method :'PUT',
headers : { "Content-Type": "application/json" },
......@@ -68,7 +71,7 @@ const update = async () => {
const response = await fetch('/user/me', requestOptions);
if (response.ok) {
const updatedUser = await response.json();
console.log(`user updated : ${JSON.stringify(updatedUser)}`);
console.log(`show infos updated : ${JSON.stringify(updatedUser)}`);
}
else {
const error = await response.json();
......@@ -76,17 +79,44 @@ const update = async () => {
}
}
const ajoutTicketShow = async (event) => {
const addTicketShow = async (event) => {
const divShow = event.target.parentElement;
const showId = divShow.id;
const nbTickets = addToTicketsList(divShow);
const ticketsData = {description : divShow.textContent.split(':')[0], tickets : nbTickets, show : divShow.id};
await update(ticketsData);
};
const addToTicketsList = (divShow) => {
let tmp;
const divTickets = document.getElementById("showTickets");
// const buttons = divShow.getElementsByClassName("ticket");
// buttons.forEach( button => {
// button.textContent = "annuler";
// button.removeEventListener("click", ajoutTicketShow);
// })
const showId = divShow.id + "-t";
if(document.getElementById(showId) === null) {
const node = document.createElement('div');
node.id = showId;
node.textContent = `${divShow.textContent.split(':')[0]}`;
const span = document.createElement('span');
span.className = "tickets";
span.textContent = 1;
node.appendChild(span);
const annulationButton = document.createElement('button');
annulationButton.className = 'annulation';
annulationButton.textContent = "Annuler";
annulationButton.addEventListener("click", cancelTicketShow);
node.appendChild(annulationButton);
divTickets.appendChild(node);
tmp = span.textContent;
}else {
const sp = document.getElementById(showId).querySelector(".tickets");
sp.textContent = 1 + parseInt(sp.textContent);
tmp = parseInt(sp.textContent);
}
return tmp;
};
const cancelTicketShow = () => {
}
const logout = async () => {
const requestOptions = {
method :'GET',
......
......@@ -55,7 +55,7 @@ const login = async (req, res) => {
return res.status(401).json({ message : 'mot de passe incorrect.'});
// create and send token
const token = jwt.sign({id: user._id}, jwtConfig.SECRET_TOKEN, {expiresIn : '500s'} );
const token = jwt.sign({id: user._id}, jwtConfig.SECRET_TOKEN, {expiresIn : '1500s'} );
console.log(`login : ${token}`);
res.cookie('token', token, { maxAge : 60000, httpOnly: true, sameSite : 'strict' }) // secure : true (avec https)
res.status(200).json({ message : 'utilisateur connecté', name : user.name, admin : user.admin });
......
......@@ -17,6 +17,7 @@ module.exports.update =
const user = await User.findByIdAndUpdate(req.userId,
updatedData,
{ new : true });
res.status(200).json({ name : user.name , message : 'mise à jour réussie'});
console.log(user);
res.status(200).json({ description : user.description , message : 'mise à jour réussie'});
}
......@@ -17,11 +17,9 @@ const userSchema = new mongoose.Schema({
type : Boolean,
default: false
},
reservedTickets: [{
show: { type: mongoose.ObjectId},
description : { type : String, unique :true, required : true},
tickets: { type: Number, required: true }
}]
show: { type: mongoose.ObjectId},
description : { type : String, unique :true, required : true},
tickets: { type: Number, required: true },
});
......
......@@ -5,7 +5,7 @@
<title>user profile</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css"/>
<script defer src="../scripts/admin-bundle.js?0d71f7f58236f8f7a2fc"></script></head>
<script defer src="../scripts/admin-bundle.js?0dfd6f030b50bdc40759"></script></head>
<body>
<h1>Application Showtime</h1>
......
......@@ -5,7 +5,7 @@
<title>login/register</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css"/>
<script defer src="../scripts/login-bundle.js?0d71f7f58236f8f7a2fc"></script></head>
<script defer src="../scripts/login-bundle.js?0dfd6f030b50bdc40759"></script></head>
<body>
<h1>Application de partage</h1>
......
......@@ -5,7 +5,7 @@
<title>login/register</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css"/>
<script defer src="../scripts/register-bundle.js?0d71f7f58236f8f7a2fc"></script></head>
<script defer src="../scripts/register-bundle.js?0dfd6f030b50bdc40759"></script></head>
<body>
<h1>Identification</h1>
......
......@@ -5,7 +5,7 @@
<title>user profile</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css"/>
<script defer src="../scripts/user-bundle.js?0d71f7f58236f8f7a2fc"></script></head>
<script defer src="../scripts/user-bundle.js?0dfd6f030b50bdc40759"></script></head>
<body>
<h1>Application Showtime</h1>
......
This diff is collapsed.
......@@ -8,7 +8,7 @@ const userController = require('../controllers/user.controller');
router.get('/', userController.home );
router.get('/me', authMiddleware.validToken, userController.me );
// router.put('/me', authMiddleware.validToken, userController.update );
router.put('/me', authMiddleware.validToken, userController.update );
module.exports = router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment