getObserved: function(uid, cursor, cb) {
db.serialize(function() {
let query =
- "SELECT id, vid, cadence, created, score, white, black " +
+ "SELECT id, vid, cadence, options, created, score, white, black " +
"FROM Games " +
"WHERE created < " + cursor + " ";
if (uid > 0) {
"ORDER BY created DESC " +
"LIMIT 20"; //TODO: 20 hard-coded...
db.all(query, (err, games) => {
+ games = games || [];
// Query players names
let pids = {};
games.forEach(g => {
if (!pids[g.black]) pids[g.black] = true;
});
UserModel.getByIds(Object.keys(pids), (err2, users) => {
+ users = users || [];
let names = {};
users.forEach(u => { names[u.id] = u.name; });
cb(
id: g.id,
vid: g.vid,
cadence: g.cadence,
+ options: g.options,
created: g.created,
score: g.score,
players: [
getRunning: function(uid, cb) {
db.serialize(function() {
let query =
- "SELECT id, vid, cadence, created, white, black " +
+ "SELECT id, vid, cadence, options, created, white, black " +
"FROM Games " +
"WHERE score = '*' AND (white = " + uid + " OR black = " + uid + ")";
db.all(query, (err, games) => {
+ games = games || [];
// Get movesCount (could be done in // with next query)
query =
"SELECT gid, COUNT(*) AS nbMoves " +
if (!pids[g.black]) pids[g.black] = true;
});
UserModel.getByIds(Object.keys(pids), (err2, users) => {
+ users = users || [];
let names = {};
users.forEach(u => { names[u.id] = u.name; });
cb(
id: g.id,
vid: g.vid,
cadence: g.cadence,
+ options: g.options,
created: g.created,
score: g.score,
movesCount: movesCounts[g.id] || 0,
getCompleted: function(uid, cursor, cb) {
db.serialize(function() {
let query =
- "SELECT id, vid, cadence, created, score, scoreMsg, " +
+ "SELECT id, vid, cadence, options, created, score, scoreMsg, " +
"white, black, deletedByWhite, deletedByBlack " +
"FROM Games " +
"WHERE " +
"ORDER BY created DESC " +
"LIMIT 20";
db.all(query, (err, games) => {
+ games = games || [];
// Query player names
let pids = {};
games.forEach(g => {
if (!pids[g.black]) pids[g.black] = true;
});
UserModel.getByIds(Object.keys(pids), (err2, users) => {
+ users = users || [];
let names = {};
users.forEach(u => { names[u.id] = u.name; });
cb(
id: g.id,
vid: g.vid,
cadence: g.cadence,
+ options: g.options,
created: g.created,
score: g.score,
scoreMsg: g.scoreMsg,