I've wrote a piece of code today that really make me sick about:
if ( account.plan_id ) {
const featuresToCheck = [];
for (const vertical of Object.keys(account.account_settings.enabled_features)) {
for (const feature of Object.keys(account.account_settings.enabled_features[vertical])){
featuresToCheck.push(`${vertical}.${feature}`);
}
}
planService.filterFeatures(account.plan_id.id,featuresToCheck).then((filtered) => {
filtered.forEach((feature) => {
const [ vert , feat] = feature.split('.');
out.account_settings.enabled_features[vert][feat].is_active = false;
});
customFieldsService.getAccountCustomFields(account_id, out)
.then(function(){
return cb();
})
.fail(cb);
});
} else {
customFieldsService.getAccountCustomFields(account_id, out)
.then(function(){
return cb();
})
.fail(cb);
}
Which could be best practice to handle cases like this? Unfortunately I cannot transform it in async/await.
customFieldsService.getAccountCustomFields
. Thanks all for the help and clarification \$\endgroup\$.fail(cb)
on the almost last line? \$\endgroup\$