Skip to content

Instantly share code, notes, and snippets.

@AdriVanHoudt
Created December 29, 2015 13:26
Show Gist options
  • Save AdriVanHoudt/1b8ceddda73020b2dc1c to your computer and use it in GitHub Desktop.
Save AdriVanHoudt/1b8ceddda73020b2dc1c to your computer and use it in GitHub Desktop.
domain stuff
// error happens because of https://github.com/AdriVanHoudt/Hapi-Boombox/blob/master/lib/index.js#L42
exports.getAll = function (request, reply) {
return Entity.getAll(request.auth.credentials.team, dbConn, (err, result) => {
if (err) {
return reply(err);
}
return Async.map(result, (item, callback) => {
if (item.id) {
return Entity.getSubStuff(item.id, dbConn, (err, stuff) => {
if (err) {
return callback(err);
}
item.stuff = stuff;
// 3: getSubStuff is done after reply with error and calls callback
return callback(null, item);
});
}
return Entity.getOtherStuff(request.auth.credentials.team, dbConn, (err, otherStuff) => {
if (err) {
// 1: errors
return callback(err);
}
item.stuff = otherStuff;
return callback(null, item);
});
}, (err, results) => {
// 2: call reply with error
// 4: reply gets called again
return reply(err, results);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment