This commit is contained in:
Charles Chong 2014-04-02 09:07:15 -07:00
Родитель c7db5ab731
Коммит 2520cf2117
2 изменённых файлов: 36 добавлений и 3 удалений

Просмотреть файл

@ -24,6 +24,7 @@ function newGame(client, data, developerID, callback) {
callback(null, data);
}
});
client.zadd('gamesByStatus:pending', Date.now(), data.id);
}
exports.newGame = newGame;
@ -120,6 +121,7 @@ function publicGameObj(full) {
'number_of_players',
'orientation',
'privacy_policy_url',
'queuePosition',
'screenshots',
'slug',
'status',

Просмотреть файл

@ -1,4 +1,5 @@
var _ = require('lodash');
var Promise = require('es6-promise').Promise;
var auth = require('../../lib/auth');
var db = require('../../db');
@ -117,10 +118,40 @@ module.exports = function(server) {
});
}
// Pick the first 'count' games
var gamesUpToCount = _.first(filteredGames, count).map(gamelib.publicGameObj);
var gamesUpToCount = _.first(filteredGames, count);
if (developerFilter) {
// Add queue position if using the developer filter
function queuePromise(game) {
return new Promise(function(resolve, reject){
if (game.status === "pending"){
client.zrank("gamesByStatus:pending", game.id,
db.plsNoError(res, done, function(rank) {
game.queuePosition = rank + 1;
done();
console.log(game)
resolve(game);
}));
} else {
resolve(game);
}
});
}
gamesUpToCount.forEach(queuePromise);
Promise.all(gamesUpToCount).then(function(gamesWithQueuePosition){
gamesWithQueuePosition.map(gamelib.publicGameObj);
res.json(gamesWithQueuePosition);
done();
}, function(err){
res.json(500, {error: err || 'db_error'});
done();
});
} else {
gamesUpToCount.map(gamelib.publicGameObj);
res.json(gamesUpToCount);
done();
}
}
}
}));
};