Skip to content

Instantly share code, notes, and snippets.

@ktkaushik
Created February 20, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktkaushik/9112357 to your computer and use it in GitHub Desktop.
Save ktkaushik/9112357 to your computer and use it in GitHub Desktop.
admin feed.js
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