Commit 09f1927e authored by Matthieu - Greep's avatar Matthieu - Greep

set voteDate so it will be the same

parent 7e89697e
Pipeline #457 passed with stage
in 49 seconds
...@@ -26,8 +26,9 @@ module.exports = function(app, sql, tokenCheck, errorHandler) { ...@@ -26,8 +26,9 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
console.log(err); console.log(err);
errorHandler(res, 500, 'Internal server error'); errorHandler(res, 500, 'Internal server error');
} else { } else {
const voteDate = new Date();
if (sqlRes.length === 0) { // Create a new vote for this player if (sqlRes.length === 0) { // Create a new vote for this player
sql.query('INSERT INTO votes (map, player, vote, date) VALUES (?, ?, ?, ?)', [mapId, player, vote, new Date()], (err)=>{ sql.query('INSERT INTO votes (map, player, vote, date) VALUES (?, ?, ?, ?)', [mapId, player, vote, voteDate], (err)=>{
if (err) { if (err) {
console.error(err); console.error(err);
errorHandler(res, 500, 'Internal server error'); errorHandler(res, 500, 'Internal server error');
...@@ -36,13 +37,13 @@ module.exports = function(app, sql, tokenCheck, errorHandler) { ...@@ -36,13 +37,13 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
mapUid: mapId, mapUid: mapId,
player: player, player: player,
vote: vote, vote: vote,
date: new Date(), date: voteDate,
type: "new" type: "new"
}); });
} }
}); });
} else { // Update the vote for this player } else { // Update the vote for this player
sql.query('UPDATE votes SET vote = ?, date = ? WHERE map = ? AND player = ?', [vote, new Date(), mapId, player], (err)=>{ sql.query('UPDATE votes SET vote = ?, date = ? WHERE map = ? AND player = ?', [vote, voteDate, mapId, player], (err)=>{
if (err) { if (err) {
console.error(err); console.error(err);
errorHandler(res, 500, 'Internal server error'); errorHandler(res, 500, 'Internal server error');
...@@ -51,7 +52,7 @@ module.exports = function(app, sql, tokenCheck, errorHandler) { ...@@ -51,7 +52,7 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
mapUid: mapId, mapUid: mapId,
player: player, player: player,
vote: vote, vote: vote,
date: new Date(), date: voteDate,
type: "update" type: "update"
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment