How to list and filter two request in one console

Viewed 56

i'm trying to list my folders and subfolders but right now it only show me the folders not both

function getParserTypes (types, subject) {
  return types.map((type) => {
    return {
      id: type.entry.id,
      name: type.entry.name,
      grade: subject.grade,
      subject: subject.id
    };
  });
}   

the first request call folders and with my second request call Subfolders

  const firstRequest = await axios.get(`${fox.url}/nodes/${firstFolderId}/children`, PARAMS);
  const secondRequest = await axios.get(`${fox.url}/nodes/${secondFolderId}/children`, PARAMS);


 const types = _(firstRequest.data.list.entries).filter((type) => !type.entry.name.includes('dog'),
      secondRequest.data.list.entries).filter((type) => !type.entry.name.includes('cat');
    
      const resourcesTypes = getParserTypes(types, subject);
    
      
      console.log("resourcesTypes",resourcesTypes)

my console display only my first Request not both

JSON

1 Answers

You are not awaiting both request. Since these are Promises, you can use Promise.all or Promise.allSettled. See this thread for difference. It returns a Promise too.

  const res1 = await axios.get(
    "https://jsonplaceholder.typicode.com/todos/1"
  );
  const res2 = await axios.get(
    "https://jsonplaceholder.typicode.com/todos/2"
  );
  const res = await Promise.all([res1, res2]);
  console.log(res);
  -------- or --------------
  Promise.all([res1, res2]).then((res) => {
      console.log(res);
  })
Related