Created
          August 21, 2015 15:45 
        
      - 
      
 - 
        
Save adamrneary/e7efc9cac377bd250e15 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
    
  
  
    
  | /** | |
| * @param {Object?} params | |
| * @return {Promise} | |
| */ | |
| exports.fetchAll = function(params) { | |
| if (params && params.teamId) { | |
| return Thrift.enhanced.Job.indexForTeam(params).then(jobs => { | |
| processForeignKeys(jobs); | |
| return jobs; | |
| }); | |
| } else { | |
| return Thrift.enhanced.Job.index().then(jobs => { | |
| processForeignKeys(jobs); | |
| return jobs; | |
| }); | |
| } | |
| }; | |
| function processForeignKeys(jobs) { | |
| _.chain(jobs) | |
| .pluck('jobTemplateId') | |
| .uniq() | |
| .value() | |
| .forEach(jobTemplateId => { | |
| JobTemplate.actions.fetch({id: jobTemplateId}); | |
| }); | |
| const teams = _.chain(jobs) | |
| .pluck('team') | |
| .uniq(record => record.id) | |
| .value(); | |
| Team.actions.receiveAll(teams); | |
| const jobUsers = _.chain(jobs) | |
| .pluck('jobUsers') | |
| .flatten() | |
| .pluck('user') | |
| .uniq(record => record.id) | |
| .value(); | |
| User.actions.receiveAll(jobUsers); | |
| const jobRoles = _.chain(jobs) | |
| .pluck('jobUsers') | |
| .flatten() | |
| .pluck('jobRole') | |
| .uniq(record => record.id) | |
| .value(); | |
| JobRole.actions.receiveAll(jobRoles); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment