all files / src/posts/ topics.js

33.33% Statements 5/15
100% Branches 0/0
9.09% Functions 1/11
33.33% Lines 5/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                               
 
'use strict';
 
var async = require('async'),
	topics = require('../topics');
 
module.exports = function(Posts) {
 
	Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) {
		async.waterfall([
			function(next) {
				Posts.getPidsFromSet(set, start, stop, reverse, next);
			},
			function(pids, next) {
				Posts.getPostsByPids(pids, uid, next);
			}
		], callback);
	};
 
	Posts.isMain = function(pid, callback) {
		async.waterfall([
			function(next) {
				Posts.getPostField(pid, 'tid', next);
			},
			function(tid, next) {
				topics.getTopicField(tid, 'mainPid', next);
			},
			function(mainPid, next) {
				next(null, parseInt(pid, 10) === parseInt(mainPid, 10));
			}
		], callback);
	};
 
	Posts.getTopicFields = function(pid, fields, callback) {
		async.waterfall([
			function(next) {
				Posts.getPostField(pid, 'tid', next);
			},
			function(tid, next) {
				topics.getTopicFields(tid, fields, next);
			}
		], callback);
	};
 
};