title: Google Cloud Functions - warning Avoid nesting promises promise/no-nesting
body: <p>Given the following function I get the warning: </p>
  
  <blockquote>
    <p>warning  Avoid nesting promises  promise/no-nesting (line 6)</p>
  </blockquote>
  
  <p>How should I re-estructure the function to fix the warning?</p>
  
  <pre><code>function FindNearbyJobs(uid, lat, lng){
    return admin.database().ref(`users/${uid}/nearbyjobs`).remove().then(data =&gt; {
      return new Promise((resolve, reject) =&gt; {
        const geoQueryJobs = geoFireJobs.query({center: [lat, lng], radius: 3 });
        geoQueryJobs.on("key_entered", (key, location, distance) =&gt; {
          return Promise.all([admin.database().ref(`jobs/${key}/category`).once('value'), admin.database().ref(`users/${uid}/account/c`).once('value')]).then(r =&gt; {
            const cP = r[0];
            const cO = r[1];
            if (cO.val().includes(cP.val())){
              return admin.database().ref(`users/${uid}/nearbyjobs/${key}`).set({ d: distance });
            }else{
              return null;
            }
          });
        });
        geoQueryJobs.on("ready", () =&gt; {
          resolve();
        });
      });
    });
  }
  </code></pre>