more changes to suggested topics

This commit is contained in:
Barış Soner Uşaklı
2018-02-02 11:55:55 -05:00
parent 9d3b00f778
commit c38edb1fd4
2 changed files with 53 additions and 21 deletions

View File

@@ -42,7 +42,7 @@ function searchInContent(data, callback) {
var matchCount = 0;
var pids;
var metadata;
var itemsPerPage = data.itemsPerPage || 10;
async.waterfall([
function (next) {
async.parallel({
@@ -99,8 +99,8 @@ function searchInContent(data, callback) {
matchCount = metadata.pids.length;
if (data.page) {
var start = Math.max(0, (data.page - 1)) * 10;
metadata.pids = metadata.pids.slice(start, start + 10);
var start = Math.max(0, (data.page - 1)) * itemsPerPage;
metadata.pids = metadata.pids.slice(start, start + itemsPerPage);
}
posts.getPostSummaryByPids(metadata.pids, data.uid, {}, next);
@@ -108,7 +108,11 @@ function searchInContent(data, callback) {
function (posts, next) {
// Append metadata to returned payload (without pids)
delete metadata.pids;
next(null, Object.assign({ posts: posts, matchCount: matchCount, pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10)) }, metadata));
next(null, Object.assign({
posts: posts,
matchCount: matchCount,
pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10)),
}, metadata));
},
], callback);
}