From 4ca3057083e08e76384d1e7b5d8516ef4a1a8a74 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Wed, 26 Feb 2014 18:50:07 -0800 Subject: [PATCH] Fixed a couple of bugs: - `getUserFromEmail` now returns an error if no user was found, which I believe is the correct behaviour, and added a check in `login.js` to account for this - `list.js` now fetches the entire game object instead of the public object so it can check the game's `status` property correctly, then maps them to public objects when returning them as a response --- lib/user.js | 2 +- views/game/list.js | 8 +++++--- views/user/login.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/user.js b/lib/user.js index 2c11d63..a304bf9 100644 --- a/lib/user.js +++ b/lib/user.js @@ -381,7 +381,7 @@ function getUserFromEmail(client, email, callback) { if (err && err !== 'no_such_user') { callback(err); } else if (!id) { - callback(null, null); + callback('no_such_user'); } else { getUserFromID(client, id, callback); } diff --git a/views/game/list.js b/views/game/list.js index a2c3c97..7310741 100644 --- a/views/game/list.js +++ b/views/game/list.js @@ -59,7 +59,7 @@ module.exports = function(server) { } var permissions = userData.permissions; - for (var p in Object.keys(permissions)) { + for (var p in permissions) { // 'status' should only be accessible to reviewers and admins if (permissions[p] && (p === 'reviewer' || p === 'admin')) { return fetchGames(); @@ -80,7 +80,7 @@ module.exports = function(server) { // TODO: Filter only 'count' games without having to fetch them all first // (will be somewhat tricky since we need to ensure order to do pagination // properly, and we use UUIDs for game keys that have no logical order in the db) - gamelib.getPublicGameObjList(client, null, function(games) { + gamelib.getGameList(client, null, function(games) { var filteredGames = games; if (statusFilter) { // Filter for games matching the provided status @@ -89,7 +89,9 @@ module.exports = function(server) { }); } // Pick the first 'count' games - var gamesUpToCount = _.first(filteredGames, count); + var gamesUpToCount = _.first(filteredGames, count).map(function(game) { + return gamelib.publicGameObj(game); + }); res.json(gamesUpToCount); done(); }); diff --git a/views/user/login.js b/views/user/login.js index 927f10a..a215e7c 100644 --- a/views/user/login.js +++ b/views/user/login.js @@ -37,7 +37,7 @@ module.exports = function(server) { var client = db.redis(); var email = body.email; user.getUserFromEmail(client, email, function(err, resp) { - if (err) { + if (err && err !== 'no_such_user') { res.json(500, {error: err}); return; }