Skip to content

Instantly share code, notes, and snippets.

@adamrneary
Created January 28, 2015 15:42
Show Gist options
  • Select an option

  • Save adamrneary/04b07b6816f4ae2ad7d4 to your computer and use it in GitHub Desktop.

Select an option

Save adamrneary/04b07b6816f4ae2ad7d4 to your computer and use it in GitHub Desktop.
// Then we will create a return object to which the functions below can add.
var returnObject = {};
// As we define each database query and its processing logic, the return value
getNextFewUsers = User
.find(query)
.where('deleted').ne(true)
.sort(sort)
.limit(limit)
.populate('company')
.exec()
.then(function(users) {
if (params.projectKey) {
users = sortUsersByProjectScore(users, params.projectKey);
}
returnObject.users = users;
});
getConsultantCount = User
.find(query)
.where('deleted').ne(true)
.where({accountType: 'USER'})
.count()
.exec()
.then(function(count) {
returnObject.numberOfCompanies = count;
});
getCompanyCount = User
.find(query)
.where('deleted').ne(true)
.where({accountType: 'COMPANY'})
.count()
.exec()
.then(function(count) {
returnObject.numberOfConsultants = count;
});
// And boom goes the dynamite.
getNextFewUsers
.then(getConsultantCount)
.then(getCompanyCount)
.then(function() {
callback(null, returnObject)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment