From afc426016772300cc2812e8f96dd964bc6ae739d Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Fri, 6 Dec 2019 21:43:53 +0100 Subject: [PATCH] Fix moves update --- client/src/views/Game.vue | 2 +- server/models/Game.js | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index b66c6ef8..114b86b4 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -452,7 +452,7 @@ export default { squares: filtered_move, message: this.corrMsg, //TODO played: Date.now(), //TODO: on server? - idx: this.game.moves.length - 1, + idx: this.game.moves.length, color: move.color, }, clocks: this.game.clocks.map((t,i) => i==colorIdx diff --git a/server/models/Game.js b/server/models/Game.js index ced56112..0e42292e 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -132,31 +132,24 @@ const GameModel = // obj can have fields move, fen and/or score update: function(id, obj) { - - - -console.log(id); - console.log(obj); - - db.parallelize(function() { let query = "UPDATE Games " + "SET "; if (!!obj.fen) - query += "fen = " + obj.fen + ","; + query += "fen = '" + obj.fen + "',"; if (!!obj.score) - query += "score = " + obj.score + ","; + query += "score = '" + obj.score + "',"; query = query.slice(0,-1); //remove last comma - query += " WHERE gameId = " + id; + query += " WHERE id = " + id; db.run(query); if (!!obj.move) { - const m =obj.move; + const m = obj.move; query = "INSERT INTO Moves (gid,squares,message,played,idx,color) VALUES " + "(" + id + ",'" + JSON.stringify(m.squares) + "','" + m.message + - "'" + m.played + "," + m.idx + ",'" + m.color + "')"; + "'," + m.played + "," + m.idx + ",'" + m.color + "')"; db.run(query); } }); -- 2.44.0