* added: datetime
*/
-const GameModel =
-{
+const GameModel = {
+
checkGameInfo: function(g) {
return (
g.vid.toString().match(/^[0-9]+$/) &&
db.serialize(function() {
let query =
"SELECT id, vid, cadence, created, score, white, black " +
- "FROM Games ";
- if (uid > 0) query +=
- "WHERE " +
- " created < " + cursor + " AND " +
- " white <> " + uid + " AND " +
- " black <> " + uid + " ";
+ "FROM Games " +
+ "WHERE created < " + cursor + " ";
+ if (uid > 0) {
+ query +=
+ " AND white <> " + uid + " " +
+ " AND black <> " + uid + " ";
+ }
query +=
"ORDER BY created DESC " +
"LIMIT 20"; //TODO: 20 hard-coded...
"(" + id + ",?," + Date.now() + "," + obj.move.idx + ")";
db.run(query, JSON.stringify(obj.move.squares));
finishAndSendQuery();
- } else cb({ errmsg: "Wrong move index" });
- } else {
+ }
+ else cb({ errmsg: "Wrong move index" });
+ }
+ else {
if (ret.maxIdx < 2) cb({ errmsg: "Time not over" });
else {
// We also need the game cadence
}
}
});
- } else finishAndSendQuery();
+ }
+ else finishAndSendQuery();
// NOTE: chat and delchat are mutually exclusive
if (!!obj.chat) {
const query =
"INSERT INTO Chats (gid, msg, name, added) VALUES ("
+ id + ",?,'" + obj.chat.name + "'," + Date.now() + ")";
db.run(query, obj.chat.msg);
- } else if (obj.delchat) {
+ }
+ else if (obj.delchat) {
const query =
"DELETE " +
"FROM Chats " +
});
});
}
-}
+
+};
module.exports = GameModel;