From: Benjamin Auder Date: Fri, 6 Dec 2019 20:43:53 +0000 (+0100) Subject: Fix moves update X-Git-Url: https://git.auder.net/variants/current/doc/css/pieces/config.php?a=commitdiff_plain;h=afc426016772300cc2812e8f96dd964bc6ae739d;p=vchess.git Fix moves update --- 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); } });