I am dispatching an action when a function is called , it should try to pass a file/image to another function to upload it to a local folder once done try to make insert into sqlite database , to ensure that these steps will be done one by one , I have used Promises , my issue is that the image is uploaded to local folder but insertion into database fails , would please help to find how I can correct get insertion into database done .
here is my code :
export const addPosts = ( imageName , data,title,categ,idSubCateg) => {
  const idSubCat = idSubCateg ? idSubCateg : 0;
  return (dispatch) => {
    dispatch({ type: ADDING_POST });
    new Promise((resolve, reject) => {   
      uploadImage(imageName, data) // this for upload image to local folder
      const postToSave = { title, imageName };                 
      resolve(registerDataIntoDtabase(dispatch,imageName,title,categ,idSubCat));
      reject(handleError(dispatch, 'an Error Occured'));
    });
  }
}
const registerDataIntoDtabase = (dispatch,title,imagenmae,categ,idSubCat) => {
  //insert into database
  new Promise((resolve, reject) => { 
    db.transaction((tx) => {
        tx.executeSql('INSERT INTO rooms (room,idHouse,title,idOwner) VALUES (?,?,?,?)', [imagenmae,categ,title,idSubCat], (tx, results) => {
          resolve(dispatch({ type: ADDING_SUCCESS }));
          reject(handleError(dispatch, error.message));
        })
    });
  });
}
 
     
     
    