-
-
Save robwormald/f37b0ea35eaae41e58c0 to your computer and use it in GitHub Desktop.
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
/** | |
* 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 countCities = City.count(); | |
var fetchCities = City.find().populate('countryId').paginate({ page: currentPage, limit: pageLimit }); | |
var doQueries = Promise.spread([countCities,fetchCities]).then(function(totalCities,fetchedCities){ | |
return { | |
cities: cities, | |
currentPage: currentPage, | |
pageCount: Math.ceil(totalCities/pageLimit) | |
}; | |
}); | |
doQueries.then(res.view); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment