score:0

Accepted answer

the problem is here:

 headers.map((conversation) =>
    conversation.conversators.filter(async (conversator) => {
      if (conversator !== user._id) {
        let conv = await getuserbyid(conversator);
        fetchedconversations.push(conv);
      }
    })
  );

you are pushing after awaiting a promise, but let the code continue on.

try this:

 await promise.all(headers.map((conversation) =>
    promise.all(conversation.conversators.filter(conversator=>conversator !== user._id)
      .map(async (conversator) => {
            let conv = await getuserbyid(conversator);
            fetchedconversations.push(conv);
    }));
  ));

map returns the promises, then you use promise.all to make them all into one promise and await it. there certainly is a better way to turn this out, but that should be enough to get you to understand what's happening.


Related Query

More Query from same tag