Skip to content

Commit

Permalink
Merge pull request CoderDojo#41 from CoderDojo/resolve-parents
Browse files Browse the repository at this point in the history
Resolve parents
  • Loading branch information
sigismondm committed Jun 30, 2015
2 parents e66d607 + 0fc3008 commit f0c68cc
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ module.exports = function(options) {
privateFilter,
publicProfilesFilter,
under13Filter,
resolveChildren
resolveChildren,
resolveParents
],function(err, profile){
if(err){
return done(err);
Expand Down Expand Up @@ -409,6 +410,34 @@ module.exports = function(options) {
return done(null, profile);
}
}

function resolveParents(profile, done){
var resolvedParents = [];

if(!_.isEmpty(profile.parents)){
async.each(profile.parents, function(parent, callback){
seneca.make$(PARENT_GUARDIAN_PROFILE_ENTITY).list$({userId: parent}, function(err, results){
if(err){
return callback(err);
}
resolvedParents.push(results[0]);
return callback();
});
}, function(err){
if(err){
return done(err);
}

profile.resolvedParents = resolvedParents;

return done(null, profile);
});
} else {
profile.resolvedParents = resolvedParents;

return done(null, profile);
}
}
}

function cmd_save(args, done) {
Expand Down

0 comments on commit f0c68cc

Please sign in to comment.