Created
February 20, 2014 12:23
-
-
Save ktkaushik/9112357 to your computer and use it in GitHub Desktop.
admin feed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts.adminFeed = function(req, res, next) { | |
var perPage = 10 | |
, page = req.params.page > 0 ? req.params.page : 0; | |
console.log("looking for admin feed ************************"); | |
var query = req.query.from; | |
Post | |
.find(req.query) | |
.limit(perPage) | |
.skip(perPage * page) | |
.sort({createdAt: 'desc'}) | |
.exec(function(err, posts) { | |
Post.count().exec(function (err, count) { | |
console.log("------- count-----------"); | |
console.log(count); | |
console.log("count/perPage"); | |
console.log(count/perPage); | |
var pages = Math.ceil((count / perPage), 10); | |
return res.format({ | |
html: function() { | |
res.render('admin/posts/adminFeed', { | |
page: page, | |
count: count, | |
posts: posts, | |
perPage: perPage, | |
pages: pages, | |
layout: 'admin/adminLayout' | |
}); | |
}, | |
json: function() { | |
res.json({ | |
posts: posts, | |
metadata: { | |
page: page, | |
count: count, | |
perPage: perPage, | |
pages: pages | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment