Looking to simplify the structure below:
Reusable service1 for IndexedDB interactions
function isDbExist (){
// do something , returning either reject or resolve
}
function createDB (){
// do something , returning either reject or resolve
}
function getData (){
// do something , returning either reject or resolve
}
In another service2, I'm injecting service1 and using the functions like this:
function1 (){
service1.isDbExist.then(function(data){
service1.createDB.then(function(data){
service1.getData.then(function(data){
referred.resolve(data);
},function(error){
deferred.reject(error)
})
},function(error){
deferred.reject(error);
})
},function(error){
deferred.reject(error);
})
}
The issue here is that the code is not very readable, making it difficult to debug which reject function corresponds to which promise. Is there a better way to handle this? I have looked into $q.all but don't think it's applicable in this scenario.