I am using promises to avoid the nesting structure created by callbacks.
However in this code I still have some nesting. Is there something I am doing wrong or is this un-avoidable in this case?
In this case I want to check and see if a profile exists and if it does not I want to create it.
DB.getProfile(id_google).then((resGet) => {
if(!resGet[0]){
console.log('PROFILE - NOT FOUND - MUST CREATE');
DB.createProfile(id_google, email, name, pic_url).then((resCreate)=>{
console.log('PROFILE CREATED');
}).catch((error) => {
console.log('ERROR - createProfile() Failed: ', error);
});
} else {
console.log('PROFILE FOUND LOCALLY');
console.log(resGet[0]);
return done(null, resGet[0])
}
}).catch((error) => {
console.log('ERROR - getOrCreateProfile() Failed: ', error);
});
};