[object promise] promise not resolving

0

I am a IONIC newbie I have following function that returns membership plan.

 

async getMembership(){
await this.Products.WooCommerceAPI().get(‘memberships/plans’).then( (data) => {
this.plans = data.data.map(e => ({

   // used spread method here to call another function that gets the price 
    ...e,
    price: this.getPlanPrice(e.access_product_ids[0]).then(async (res) => {
      return  await res;
    }),
  }));
}).catch((error) => {
  // Invalid request, for 4xx and 5xx statuses
  console.log('Response Status:', error.response.status);
  console.log('Response Headers:', error.response.headers);
  console.log('Response Data:', error.response.data);
})
.finally(() => {
  // Always executed.
});
console.log(this.plans);

}

in this function I used another function that gets price of each membership using ... spread method.

    async getPlanPrice(id): Promise<any> {
    if (id !== undefined) {
      return await this.Products.WooCommerceAPI().get('products/' + id).then(data => {
        return data.data;
      });
    } else {
      return 0;
    }
  }

but the problem is

price: this.getPlanPrice(e.access_product_ids[0]).then(async (res) => {
          return  await res;
        }),

this part return [Object Promise] I have tried everything but can’t get price for example 500 insdeat of this object promise.

I would recommend forgetting that async and await exist, because you seem to be under the (completely understandable, because of the way they are often marketed) impression that they magically make asynchronous things behave synchronously.

Instead, look into RxJS operators like switchMap and mergeMap that are designed to deal with the fundamental operation you seem to be interested in here: chaining asynchronous requests. At the very least, accept that when you call something returning a Promise, if you are the final consumer, you have to take that Promise and hang a then clause off it. If you are not the final consumer, then while you can transform the Promise, you cannot unwrap it, so you must in turn return a future of some sort, not the raw underlying data.