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

code review

parent f3560584
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ const addToList = (show,list) => {
list.appendChild(node);
}
// fetch DELETE to delete one task with given task id
// fetch DELETE to delete one task with given show id
const deleteShow =
async showId => {
const requestOptions = {
......@@ -59,7 +59,7 @@ const deleteShow =
}
}
// fetch POST to create one task
// fetch POST to create one show
const createShow =
async () => {
const newShowData = {
......
......@@ -11,8 +11,8 @@ window.addEventListener('DOMContentLoaded', setup);
const getUser = async () => {
const requestOptions = {
method :'GET',
};
method: 'GET',
};
const response = await fetch('/me', requestOptions);
if (response.ok) {
const user = await response.json();
......@@ -26,15 +26,15 @@ const getUser = async () => {
const displayShowList = async () => {
const requestOptions = {
method : 'GET'
};
const response = await fetch('/admin/items', requestOptions)
method: 'GET'
};
const response = await fetch('/items', requestOptions)
if (response.ok) {
const allShows = await response.json();
//(ici : code exploitation de allShows)
const list = document.getElementById('list');
list.textContent = '';
allShows.forEach( show => addToList(show, list) );
allShows.forEach(show => addToList(show, list));
}
else {
const error = await response.json();
......@@ -42,32 +42,32 @@ const displayShowList = async () => {
}
}
const addToList = (show,list) => {
const node = document.createElement('div');
node.id = show._id;
node.className = "show";
const span = document.createElement('span');
span.className = "places";
span.textContent = `${show.places} places`
node.textContent = `${show.description} : `;
node.appendChild(span);
//
const ticketsButton = document.createElement('button');
ticketsButton.className = 'ticket';
ticketsButton.addEventListener('click', addTicketShow);
ticketsButton.textContent = '+1 tickets';
node.appendChild(ticketsButton);
//
list.appendChild(node);
const addToList = (show, list) => {
const node = document.createElement('div');
node.id = show._id;
node.className = "show";
const span = document.createElement('span');
span.className = "places";
span.textContent = `${show.places} places`
node.textContent = `${show.description} : `;
node.appendChild(span);
//
const ticketsButton = document.createElement('button');
ticketsButton.className = 'ticket';
ticketsButton.addEventListener('click', addTicketShow);
ticketsButton.textContent = '+1 tickets';
node.appendChild(ticketsButton);
//
list.appendChild(node);
}
const update = async (data) => {
const update = async (data) => {
const body = JSON.stringify(data);
const requestOptions = {
method :'PUT',
headers : { "Content-Type": "application/json" },
body : body
};
method: 'PUT',
headers: { "Content-Type": "application/json" },
body: body
};
const response = await fetch('/tickets', requestOptions);
if (response.ok) {
const updatedUser = await response.json();
......@@ -81,12 +81,12 @@ const update = async (data) => {
const displayTicketsList = async () => {
const requestOptions = {
method : 'GET'
};
method: 'GET'
};
const response = await fetch('/tickets', requestOptions)
if (response.ok) {
const allTickets = await response.json();
allTickets.forEach( ticket => addTicketsToList(ticket) );
allTickets.forEach(ticket => addTicketsToList(ticket));
}
else {
const error = await response.json();
......@@ -97,13 +97,13 @@ const displayTicketsList = async () => {
const addTicketsToList = (ticket) => {
const list = document.getElementById("showTickets");
createDivTickets(ticket, list);
}
}
const addTicketShow = async (event) => {
const divShow = event.target.parentElement;
const showId = divShow.id;
const description = divShow.textContent.split(':')[0];
const ticket = {show : showId, description : description, tickets : 1};
const ticket = { show: showId, description: description, tickets: 1 };
const list = document.getElementById("showTickets");
const nbTickets = addToTicketsList(ticket, list);
......@@ -113,11 +113,11 @@ const addTicketShow = async (event) => {
const addToTicketsList = (ticket, list) => {
let nbTickets;
if(document.getElementById(ticket.show+"-t") === null) {
if (document.getElementById(ticket.show + "-t") === null) {
createDivTickets(ticket, list);
nbTickets = 1;
}else {
const sp = document.getElementById(ticket.show+"-t").querySelector(".tickets");
} else {
const sp = document.getElementById(ticket.show + "-t").querySelector(".tickets");
sp.textContent = 1 + parseInt(sp.textContent);
nbTickets = parseInt(sp.textContent);
}
......@@ -150,8 +150,8 @@ const cancelTicketShow = async (event) => {
const showId = ticketDiv.id.split('-')[0];
const body = JSON.stringify(showId);
const requestOptions = {
method :'DELETE',
};
method: 'DELETE',
};
const response = await fetch(`/${showId}`, requestOptions);
if (response.ok) {
const updatedUser = await response.json();
......@@ -165,17 +165,17 @@ const cancelTicketShow = async (event) => {
const logout = async () => {
const requestOptions = {
method :'GET',
};
method: 'GET',
};
const response = await fetch(`/access/logout`, requestOptions);
if (response.ok) {
window.location.href= '/';
window.location.href = '/';
}
}
const handleError = error => {
if (error.redirectTo)
window.location.href= error.redirectTo;
window.location.href = error.redirectTo;
else
console.log(`erreur : ${error.message}`);
}
\ No newline at end of file
const displayList = async () => {
const requestOptions = {
method : 'GET'
};
const response = await fetch('/items', requestOptions)
const allShows = await response.json();
//(ici : code exploitation de allShows)
const list = document.getElementById('list');
list.textContent = '';
allShows.forEach( show => addToList(show, list) );
}
const addToList = (show,list) => {
const node = document.createElement('div');
node.className = 'show';
node.textContent = `${show.description} (${show.places})`;
//
//node.addEventListener('mouseover', () => getTask(show._id));
//
const deleteButton = document.createElement('button');
deleteButton.className = 'ticket';
deleteButton.addEventListener('click', () => deleteShow(show._id));
deleteButton.textContent = '+1 tickets';
node.appendChild(deleteButton);
//
list.appendChild(node);
}
module.exports.displayList = displayList;
\ No newline at end of file
......@@ -4,42 +4,49 @@ body {
}
div {
width : 280px;
margin : auto;
padding : 2px;
text-align :center;
width: 280px;
margin: auto;
padding: 2px;
text-align: center;
overflow: hidden;
box-sizing: border-box;
border: solid thin #999;
}
div label {
padding : 7px;
padding: 7px;
}
input {
text-align :center;
text-align: center;
}
#place {
width: 10px;
}
button {
padding : 3px;
width : 100px;
margin : 0px 5px;
font-weight : bold;
padding: 3px;
width: 100px;
margin: 0px 5px;
font-weight: bold;
}
#shows, #tickets {
margin : 10px;
padding : 4px;
border : solid thin #999;
padding: 4px;
border: solid thin #999;
}
#list, #shows {
padding : 2px;
margin : 4px 4px;
padding: 2px;
}
#list, #showTickets{
overflow: auto;
}
.tickets {
width : 50px;
width: 50px;
color: green;
}
......@@ -48,13 +55,14 @@ div.reservation:nth-of-type(even), div.show:nth-of-type(even) {
}
#userdata {
background-color : #DDD;
background-color: #DDD;
}
#userdata div{
text-align : center;
margin : 2px;
#userdata div {
text-align: center;
margin: 2px;
}
#controls {
margin-top : 10px;
margin-top: 10px;
}
......@@ -4,42 +4,49 @@ body {
}
div {
width : 280px;
margin : auto;
padding : 2px;
text-align :center;
width: 280px;
margin: auto;
padding: 2px;
text-align: center;
overflow: hidden;
box-sizing: border-box;
border: solid thin #999;
}
div label {
padding : 7px;
padding: 7px;
}
input {
text-align :center;
text-align: center;
}
#place {
width: 10px;
}
button {
padding : 3px;
width : 100px;
margin : 0px 5px;
font-weight : bold;
padding: 3px;
width: 100px;
margin: 0px 5px;
font-weight: bold;
}
#shows, #tickets {
margin : 10px;
padding : 4px;
border : solid thin #999;
padding: 4px;
border: solid thin #999;
}
#list, #shows {
padding : 2px;
margin : 4px 4px;
padding: 2px;
}
#list, #showTickets{
overflow: auto;
}
.tickets {
width : 50px;
width: 50px;
color: green;
}
......@@ -48,13 +55,14 @@ div.reservation:nth-of-type(even), div.show:nth-of-type(even) {
}
#userdata {
background-color : #DDD;
background-color: #DDD;
}
#userdata div{
text-align : center;
margin : 2px;
#userdata div {
text-align: center;
margin: 2px;
}
#controls {
margin-top : 10px;
margin-top: 10px;
}
......@@ -6,10 +6,8 @@ const authMiddleware = require('../middlewares/authentication.middleware');
router.get('/', adminController.home );
router.get('/me', authMiddleware.validToken, adminController.me );
router.get('/items', authMiddleware.validToken, adminController.list);
router.get('/items', authMiddleware.validToken, authMiddleware.isAdmin, adminController.list);
router.post('/items', authMiddleware.validToken, authMiddleware.isAdmin, adminController.create);
router.delete('/:showId', authMiddleware.validToken, authMiddleware.isAdmin, adminController.deleteShow);
// router.put('/me', authMiddleware.validToken, adminController.update );
module.exports = router;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment