From 60905b2e218b680ec9d34f9567288b27b38e622b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 22 Feb 2014 16:48:58 -0500 Subject: [PATCH] getPidPage fix, pids are strings --- src/posts.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/posts.js b/src/posts.js index 441b638e82..b010ef19b5 100644 --- a/src/posts.js +++ b/src/posts.js @@ -474,31 +474,31 @@ var db = require('./database'), } Posts.getPidPage = function(pid, uid, callback) { - Posts.getPostField(pid, 'tid', function(err, tid) { - if(err) { - return callback(err); - } - - topics.getPids(tid, function(err, pids) { - if(err) { - return callback(err); - } - - var index = pids.indexOf(pid); + if(!pid) { + return callback(new Error('invalid-pid')); + } + var index = 0; + async.waterfall([ + function(next) { + Posts.getPostField(pid, 'tid', next); + }, + function(tid, next) { + topics.getPids(tid, next); + }, + function(pids, next) { + index = pids.indexOf(pid.toString()); if(index === -1) { - return callback(new Error('pid not found')); + return next(new Error('pid not found')); } - - user.getSettings(uid, function(err, settings) { - if(err) { - return callback(err); - } - - var page = Math.ceil((index + 1) / settings.postsPerPage); - callback(null, page); - }); - }); - }); + next(); + }, + function(next) { + user.getSettings(uid, next); + }, + function(settings, next) { + next(null, Math.ceil((index + 1) / settings.postsPerPage)); + } + ], callback); }; Posts.getPidIndex = function(pid, callback) {