I am trying to get a nested Promise.all * map logic to work. I keep getting undefined values when I reach getData2.
exports.getData = (param1, param2) => {
return getData0(param1, param2)
.then(data0 => Promise.all(data0.map(e => getData1(e.id))))
.then(data1 => Promise.all(data1.map(i => getData2(i.id))))
.then(data2 => data2.map(a => getData3(a.id)))
.catch(err => console.error(err.message));
};
P.S: 1. getData0 to getData1 return structures (e.g. { a: val1, b: val2 }) 2. I assume the problem is in the way getData's are written. I suspect they should return promises. Can anyone give me a dummy example about a function that returns a structure wherein both elements of the (see a and b above) are obtained in an async way?
Thanks!