This fn is a part of a middleware that intends to populate array of PROVIDERS with an array of ENCOUNTERS.
When I console.log(provider['ENCOUNTERS'])
then I do get the encounters :
console.log(provider['ENCOUNTERS'])
But when I console.log(provider)
in the same place, I don't get encounters : console.log(provider)
I think that's why the commented console.log(network.PROVIDERS)
doesn't contain ENCOUNTERS.
populateEncounters = async()=>{
var promises = [];
network.PROVIDERS.forEach((provider)=>{
promises.push(
(async (provider)=>{
const e = await Encounter.find({
PROVIDER:provider._id
})
return e;
})(provider)
.then((e)=>{
provider['ENCOUNTERS'] = e;
console.log(provider['ENCOUNTERS']);
})
.catch ((error) => {
console.log('Error: ', error);
})
);
});
Promise.all(promises).then(() => {
// console.log(network.PROVIDERS)
res.network = network;
next()
});
}
await populateEncounters();