From c0712583f2e855c1a9ec54b3c4da076b97d99f7e Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 17 Jan 2014 12:49:21 -0500 Subject: [PATCH] fixed category sockets --- public/src/forum/category.js | 6 +++++- src/categories.js | 8 +++++--- src/socket.io/categories.js | 8 ++++++-- tests/categories.js | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index e4d36d78f4..56ea94b6e4 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -133,7 +133,11 @@ define(['composer'], function(composer) { cid: cid, after: $('#topics-container').children('.category-item').length }, function (err, data) { - if (!err && data.topics.length) { + if(err) { + return app.alertError(err.message); + } + + if (data && data.topics.length) { Category.onTopicsLoaded(data.topics); } loadingMoreTopics = false; diff --git a/src/categories.js b/src/categories.js index 6312ff835e..465ee43d81 100644 --- a/src/categories.js +++ b/src/categories.js @@ -124,9 +124,11 @@ var db = require('./database.js'), Categories.getCategoryTopics = function(cid, start, stop, uid, callback) { Categories.getTopicIds(cid, start, stop, function(err, tids) { - topics.getTopicsByTids(tids, cid, uid, function(err, topicsData) { - callback(err, topicsData); - }); + if(err) { + return callback(err); + } + + topics.getTopicsByTids(tids, cid, uid, callback); }); }; diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index 43c5a002b8..545635750d 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -11,11 +11,15 @@ SocketCategories.get = function(socket, data, callback) { }; SocketCategories.loadMore = function(socket, data, callback) { + if(!data) { + return callback(new Error('invalid data')); + } + var start = data.after, end = start + 9; - categories.getCategoryTopics(data.cid, start, end, socket.uid, function(topics) { - callback(null, { + categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, topics) { + callback(err, { topics: topics }); }); diff --git a/tests/categories.js b/tests/categories.js index 070a71e884..009d195e92 100644 --- a/tests/categories.js +++ b/tests/categories.js @@ -44,7 +44,7 @@ describe('Categories', function() { describe('.getCategoryTopics', function() { it('should return a list of topics', function(done) { - Categories.getCategoryTopics(categoryObj.cid, 0, 10, 0, function(topics) { + Categories.getCategoryTopics(categoryObj.cid, 0, 10, 0, function(err, topics) { assert(Array.isArray(topics)); assert(topics.every(function(topic) { return topic instanceof Object;