@ -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;
@ -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);
});
return callback(err);
topics.getTopicsByTids(tids, cid, uid, callback);
};
@ -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
@ -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;