static fetchReviewsByRestaurantId(id, callback) {
    let cached = false;

    this.restaurantsDb.selectReviewsByRestaurantId(this.restaurantsDb.reviewsTable, id)
      .then(reviews => {
        if (reviews.length && !cached) {
          cached = true
          this.restaurantsDb.selectReviewsByRestaurantId(this.restaurantsDb.pendingReviewsTable, id)
            .then(pendingReviews => {
              if (pendingReviews.length) {
                return callback(null, [...reviews, ...pendingReviews])
              } else {
                return callback(null, reviews)
              }
            }).catch(() => {
              return callback(null, reviews)
            })
        } else {
          fetch(`${this.DATABASE_URL}reviews/?restaurant_id=${id}`)
          .then(response => {
            if (response.status === 200) {
              return response.json();
            } else { // Oops!. Got an error from server.
              const error = (`Request failed. Returned status of ${response.status}`);
              callback(error, null);
            }
          })
          .then(response => {
            const reviews = response;
            callback(null, reviews);
          });
        }
      });
  }
/**
   * Fetch reviews based on restaurant's ID.
   */
Fetch reviews based on restaurant's ID.
Fetch reviews based on restaurant ' s ID .
static fetchReviewsByRestaurantId(id, callback) {
    let cached = false;
    this.restaurantsDb.selectReviewsByRestaurantId(this.restaurantsDb.reviewsTable, id)
      .then(reviews => {
        if (reviews.length && !cached) {
          cached = true
          this.restaurantsDb.selectReviewsByRestaurantId(this.restaurantsDb.pendingReviewsTable, id)
            .then(pendingReviews => {
              if (pendingReviews.length) {
                return callback(null, [...reviews, ...pendingReviews])
              } else {
                return callback(null, reviews)
              }
            }).catch(() => {
              return callback(null, reviews)
            })
        } else {
          fetch(`${this.DATABASE_URL}reviews/?restaurant_id=${id}`)
          .then(response => {
            if (response.status === 200) {
              return response.json();
            } else { 
              const error = (`Request failed. Returned status of ${response.status}`);
              callback(error, null);
            }
          })
          .then(response => {
            const reviews = response;
            callback(null, reviews);
          });
        }
      });
  }
static fetchReviewsByRestaurantId ( id , callback ) { let cached = false ; this . restaurantsDb . selectReviewsByRestaurantId ( this . restaurantsDb . reviewsTable , id ) . then ( reviews => { if ( reviews . length && ! cached ) { cached = true this . restaurantsDb . selectReviewsByRestaurantId ( this . restaurantsDb . pendingReviewsTable , id ) . then ( pendingReviews => { if ( pendingReviews . length ) { return callback ( null , [ ... reviews , ... pendingReviews ] ) } else { return callback ( null , reviews ) } } ) . catch ( ( ) => { return callback ( null , reviews ) } ) } else { fetch ( ` ${ this . DATABASE_URL } ${ id } ` ) . then ( response => { if ( response . status === 200 ) { return response . json ( ) ; } else { const error = ( ` ${ response . status } ` ) ; callback ( error , null ) ; } } ) . then ( response => { const reviews = response ; callback ( null , reviews ) ; } ) ; } } ) ; }
Fetch reviews based on restaurant's ID.
Fetch reviews based on restaurant ' s ID .
// Oops!. Got an error from server.