Created
November 30, 2014 00:57
-
-
Save anonymous/b57fb71432c362833d18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* CityController | |
* | |
* @description :: Server-side logic for managing cities | |
* @help :: See http://links.sailsjs.org/docs/controllers | |
*/ | |
module.exports = { | |
/* | |
* | |
*/ | |
index: function (req, res, next) { | |
var currentPage = 1; | |
var pageLimit = 15; | |
if (req.query.page != 'undefined') | |
currentPage = req.query.page; | |
var totalCities = 0; | |
City.count(function (err, totalCities) { | |
if (err) return console.log(err); | |
City.find().populate('countryId').paginate({ page: currentPage, limit: pageLimit }).exec(function (err, cities) { | |
if (err) return next(err); | |
res.view({ | |
cities: cities, | |
currentPage: currentPage, | |
pageCount: Math.ceil(totalCities/pageLimit) | |
}); | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment