X-Git-Url: https://git.auder.net/images/pieces/current/gitweb.js?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=3fde91f8cb03b9b6fdcec573995777a35c53ce15;hb=db1f1f9adb920605c7a16b060a7737e54636ee08;hp=21ece2f181a872434662dedce1fa4b878acab835;hpb=e891730f77312340d68bb7ef72a4207541fa3914;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 21ece2f1..3fde91f8 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -91,11 +91,18 @@ const GameModel = db.all(query, (err2,players) => { if (light) { - const game = Object.assign({}, - gameInfo, - {players: players} - ); - cb(null, game); + query = + "SELECT COUNT(*) AS nbMoves " + + "FROM Moves " + + "WHERE gid = " + id; + db.get(query, (err,ret) => { + const game = Object.assign({}, + gameInfo, + {players: players}, + {movesCount: ret.nbMoves} + ); + cb(null, game); + }); } else { @@ -235,7 +242,6 @@ const GameModel = query += modifs + " WHERE id = " + id; db.run(query); } - let wrongMoveIndex = false; if (obj.move) { // Security: only update moves if index is right @@ -263,6 +269,14 @@ const GameModel = + id + ",?,'" + obj.chat.name + "'," + Date.now() + ")"; db.run(query, obj.chat.msg); } + else if (obj.delchat) + { + query = + "DELETE " + + "FROM Chats " + + "WHERE gid = " + id; + db.run(query, cb); + } }); },