Created
January 28, 2015 15:42
-
-
Save adamrneary/04b07b6816f4ae2ad7d4 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
| // 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