* message: text
* played: datetime
* idx: integer
- * color: character
*/
const GameModel =
if (!!err2)
return cb(err2);
query =
- "SELECT squares, message, played, idx, color " +
+ "SELECT squares, message, played, idx " +
"FROM Moves " +
"WHERE gid = " + id;
db.all(query, (err3,moves) => {
"SELECT gid " +
"FROM Players " +
"WHERE uid " + (excluded ? "<>" : "=") + " " + uid;
- db.run(query, (err,gameIds) => {
+ db.all(query, (err,gameIds) => {
if (!!err)
return cb(err);
gameIds = gameIds || []; //might be empty
let gameArray = [];
- gameIds.forEach(gidRow => {
- GameModel.getOne(gidRow["gid"], (err2,game) => {
+ for (let i=0; i<gameIds.length; i++)
+ {
+ GameModel.getOne(gameIds[i]["gid"], (err2,game) => {
if (!!err2)
return cb(err2);
gameArray.push(game);
+ // Call callback function only when gameArray is complete:
+ if (i == gameIds.length - 1)
+ return cb(null, gameArray);
});
- });
- return cb(null, gameArray);
+ }
});
});
},
{
const m = obj.move;
query =
- "INSERT INTO Moves (gid,squares,message,played,idx,color) VALUES " +
+ "INSERT INTO Moves (gid, squares, message, played, idx) VALUES " +
"(" + id + ",'" + JSON.stringify(m.squares) + "','" + m.message +
- "'," + m.played + "," + m.idx + ",'" + m.color + "')";
+ "'," + m.played + "," + m.idx + ")";
db.run(query);
}
});