Commit 65845954 authored by Dennis Willers's avatar Dennis Willers 🏀

Fix Vote Update Bug

parent 238b8299
Pipeline #430 passed with stages
in 2 minutes and 43 seconds
...@@ -33,7 +33,6 @@ function createRouter(db) { ...@@ -33,7 +33,6 @@ function createRouter(db) {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error in hasMap'}); res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error in hasMap'});
} else { } else {
numberResults = results[0].Maps; numberResults = results[0].Maps;
console.log(numberResults);
if (numberResults === 1) next(); if (numberResults === 1) next();
else if (numberResults === 0) addMap(req, res, next); else if (numberResults === 0) addMap(req, res, next);
else res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'There are multiple maps with the same id'}); else res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'There are multiple maps with the same id'});
...@@ -113,7 +112,7 @@ function createRouter(db) { ...@@ -113,7 +112,7 @@ function createRouter(db) {
const userId = req.body.userId; const userId = req.body.userId;
const mapId = req.body.mapId; const mapId = req.body.mapId;
const vote = req.body.vote; const vote = req.body.vote;
const sql = 'UPDATE Vote SET userId = \"'+ userId + '\", mapId = \"'+ mapId + '\", vote = \"' + vote +'\" WHERE userID = \"'+ userId +'\";'; const sql = 'UPDATE Vote SET userId = \"'+ userId + '\", mapId = \"'+ mapId + '\", vote = \"' + vote +'\" WHERE userID = \"'+ userId +'\" AND mapId = \"' + mapId + '\";';
console.log('Update Vote: ', sql); console.log('Update Vote: ', sql);
db.query( db.query(
sql, sql,
......
...@@ -31,6 +31,10 @@ function sendRequest(url, json, callback) { ...@@ -31,6 +31,10 @@ function sendRequest(url, json, callback) {
}); });
} }
/*function addMapToClient(clintList, client, mapId) {
const clientId = client.name;
}*/
module.exports = { module.exports = {
isJsonString, isJsonString,
checkIfRequestHasVote, checkIfRequestHasVote,
......
...@@ -238,19 +238,16 @@ client.on('data',function(data){ ...@@ -238,19 +238,16 @@ client.on('data',function(data){
// 87.78.129.86 | localhost // 87.78.129.86 | localhost
const testClient = net.connect({host: 'localhost', port: 3000}, () => { /*const testClient = net.connect({host: 'localhost', port: 3000}, () => {
console.log('connected to server!'); console.log('connected to server!');
//testClient.write('Hello World Client!\r\n'); //testClient.write('Hello World Client!\r\n');
testClient.write(JSON.stringify({ testClient.write(JSON.stringify({"mapId":"7fsfRSUCQ7YwfBEdRk_GivW6qzj","userId":"aKBNg9fbReqLedLiz1KFfA","name":"Summer 2021 - 01"}));
"mapId":"7fsfRSUCQ7YwfBEdRk_GivW6qzj","userId":"aKBNg9fbReqLedLiz1KFfA","name":"Summer 2021 - 01"
//"vote": 80
}));
//test(testClient); //test(testClient);
}); });
testClient.on('data', (data) => { testClient.on('data', (data) => {
console.log(data.toString()); console.log(data.toString());
testClient.end(); //testClient.end();
}); });
/*testClient.on('end', () => { /*testClient.on('end', () => {
console.log('disconnected from server'); console.log('disconnected from server');
......
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