From e0377fc54853bb91e97d6ffc9009cfde51a281bf Mon Sep 17 00:00:00 2001 From: Umbra Sheep Date: Sun, 30 Sep 2018 19:55:31 +1300 Subject: [PATCH] Added users to games in sample data --- api/config/db.js | 2 +- api/res/setup_sql.sql | 6 +++++- api/v1/api.js | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/config/db.js b/api/config/db.js index 7c2e3a7..e6227b0 100644 --- a/api/config/db.js +++ b/api/config/db.js @@ -9,7 +9,7 @@ exports.connect = function(done){ state.pool = mysql.createPool({ host: 'localhost', user: 'root', - password: '', + password: 'root', port: 3306, database: "territory-walker", //multipleStatements: true diff --git a/api/res/setup_sql.sql b/api/res/setup_sql.sql index 62e5af7..d539e48 100644 --- a/api/res/setup_sql.sql +++ b/api/res/setup_sql.sql @@ -63,13 +63,17 @@ BEGIN DECLARE lastid VARCHAR(36) DEFAULT UUID(); INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES (gID, lastid, usID, a); - SELECT * FROM `polygonArea` WHERE polygonID = lastid; + SELECT * FROM `polygonArea` + JOIN userJoinedGames ON + userJoinedGames.userID = polygonArea.userID AND userJoinedGames.gameID = polygonArea.gameID + WHERE polygonID = lastid; END // DELIMITER ; INSERT INTO `gameInstances` (gameID) VALUES ("samdum"); INSERT INTO `users` (userID, nickname) VALUES ("samded", "Lesmaux"); INSERT INTO `users` (userID, nickname) VALUES ("fanded", "Umbra Sheep"); +INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("samded", "samdum", "0000FF"); INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES ("samdum", "someuniqueid", "samded", 100000.1); INSERT INTO `polygonPoints` (polygonID, lat, lng) VALUES diff --git a/api/v1/api.js b/api/v1/api.js index a3c1196..9d5a2ee 100644 --- a/api/v1/api.js +++ b/api/v1/api.js @@ -7,7 +7,11 @@ module.exports = { if (req.query.gameID != null) { let query = "CALL getPolygonPoints(\"" + req.query.gameID + "\");"; db.get().query(query, function(err, rows){ - if (err) return res.send(400); + if (err) { + console.log(err); + return res.send(400); + } + // console.log(rows); res.send(rows[0]); return; }); @@ -20,7 +24,6 @@ module.exports = { let gameID = req.body.gameID; let userID = req.body.userID; let points = JSON.parse(req.body.points); - console.log(points); if (points.length < 2) { res.send([]); } else {