updateDeliveryInfo() {
    this.log('polling this status');

    return API
      .get(`deliveries/${this.delivery_id}`)
      .then(data => {
        this.log('Receive API this data', data);

        // Reset the number of failures when we successfully poll uber
        this.pollingFailures = 0;

        if (!this.courier) {
          this.courier = new Courier(data.courier);
          this.courier.on('moved', data => this.emit('location', data));
        }
        else {
          this.courier.update(data.courier);
        }

        if (!this.pickup && data.pickup) {
          this.pickup = new Pickup(data.pickup);
          this.pickup.eta = data.pickup.eta;
        }

        if (!this.dropoff && data.dropoff) {
          this.dropoff = new Dropoff(data.dropoff);
          this.dropoff.eta = data.dropoff.eta;
        }

        const status = (data || {}).status || 'unknown';
        this.status = data.status;

        // Emit the status event before determining if the current status is terminal
        this.emit('status', status);

        switch (data.status) {
          case 'completed':
          case 'returned':
          case 'client_canceled':
          case 'no_couriers_available':
          case 'unable_to_deliver':
            // terminal statuses: we stop polling if we receive one of these
            this.complete(status);
        }
      })
      .catch(err => {
        // Increment the number of polling failures on failure
        this.pollingFailures += 1;
        this.log(err.message, err.stack);
        throw err;
      });
  }
/**
   * Call the delivery API for the latest information on this order
   */
Call the delivery API for the latest information on this order
Call the delivery API for the latest information on this order
updateDeliveryInfo() {
    this.log('polling this status');
    return API
      .get(`deliveries/${this.delivery_id}`)
      .then(data => {
        this.log('Receive API this data', data);
        this.pollingFailures = 0;
        if (!this.courier) {
          this.courier = new Courier(data.courier);
          this.courier.on('moved', data => this.emit('location', data));
        }
        else {
          this.courier.update(data.courier);
        }
        if (!this.pickup && data.pickup) {
          this.pickup = new Pickup(data.pickup);
          this.pickup.eta = data.pickup.eta;
        }
        if (!this.dropoff && data.dropoff) {
          this.dropoff = new Dropoff(data.dropoff);
          this.dropoff.eta = data.dropoff.eta;
        }
        const status = (data || {}).status || 'unknown';
        this.status = data.status;
        this.emit('status', status);
        switch (data.status) {
          case 'completed':
          case 'returned':
          case 'client_canceled':
          case 'no_couriers_available':
          case 'unable_to_deliver':
            this.complete(status);
        }
      })
      .catch(err => {
        this.pollingFailures += 1;
        this.log(err.message, err.stack);
        throw err;
      });
  }
updateDeliveryInfo ( ) { this . log ( 'polling this status' ) ; return API . get ( ` ${ this . delivery_id } ` ) . then ( data => { this . log ( 'Receive API this data' , data ) ; this . pollingFailures = 0 ; if ( ! this . courier ) { this . courier = new Courier ( data . courier ) ; this . courier . on ( 'moved' , data => this . emit ( 'location' , data ) ) ; } else { this . courier . update ( data . courier ) ; } if ( ! this . pickup && data . pickup ) { this . pickup = new Pickup ( data . pickup ) ; this . pickup . eta = data . pickup . eta ; } if ( ! this . dropoff && data . dropoff ) { this . dropoff = new Dropoff ( data . dropoff ) ; this . dropoff . eta = data . dropoff . eta ; } const status = ( data || { } ) . status || 'unknown' ; this . status = data . status ; this . emit ( 'status' , status ) ; switch ( data . status ) { case 'completed' : case 'returned' : case 'client_canceled' : case 'no_couriers_available' : case 'unable_to_deliver' : this . complete ( status ) ; } } ) . catch ( err => { this . pollingFailures += 1 ; this . log ( err . message , err . stack ) ; throw err ; } ) ; }
Call the delivery API for the latest information on this order
Call the delivery API for the latest information on this order
// Reset the number of failures when we successfully poll uber // Emit the status event before determining if the current status is terminal // terminal statuses: we stop polling if we receive one of these // Increment the number of polling failures on failure