waterfall for topics

This commit is contained in:
barisusakli
2015-08-07 17:25:35 -04:00
parent 0534da0ed1
commit 8f98d03239
2 changed files with 82 additions and 76 deletions

View File

@@ -2,7 +2,8 @@
'use strict';
var db = require('../database'),
var async = require('async'),
db = require('../database'),
posts = require('../posts');
@@ -19,24 +20,22 @@ module.exports = function(Topics) {
};
Topics.getUids = function(tid, callback) {
Topics.getPids(tid, function(err, pids) {
if (err) {
return callback(err);
}
posts.getPostsFields(pids, ['uid'], function(err, postData) {
if (err) {
return callback(err);
}
async.waterfall([
function(next) {
Topics.getPids(tid, next);
},
function(pids, next) {
posts.getPostsFields(pids, ['uid'], next);
},
function(postData, next) {
var uids = postData.map(function(post) {
return post && post.uid;
}).filter(function(uid, index, array) {
return array.indexOf(uid) === index;
return uid && array.indexOf(uid) === index;
});
callback(null, uids);
});
});
next(null, uids);
}
], callback);
};
};