Skip to content

Instantly share code, notes, and snippets.

@robwormald
Forked from anonymous/CityController.js
Last active August 29, 2015 14:10
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 robwormald/f37b0ea35eaae41e58c0 to your computer and use it in GitHub Desktop.
Save robwormald/f37b0ea35eaae41e58c0 to your computer and use it in GitHub Desktop.
/**
* 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