Created
March 11, 2023 04:12
-
-
Save bbachi/5bd39720e636357ea86639bb13b6eb36 to your computer and use it in GitHub Desktop.
Sequential Calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
async function getUsers() { | |
return await axios.get('/api/users'); | |
} | |
async function getContacts() { | |
return await axios.get('/api/contacts'); | |
} | |
async function getAddresses() { | |
return await axios.get('/api/addresses'); | |
} | |
export async function getUserInfo() { | |
try{ | |
const users = await getUsers(); | |
const contacts = await getContacts(); | |
const addresses = await getAddresses(); | |
const result = []; | |
users.data.map((user) => { | |
result.push({ | |
...user, | |
...contacts.data.find((contact) => contact.userId === user.userId), | |
...addresses.data.find((address) => address.userId === address.userId)}) | |
}); | |
console.log(result) | |
return result; | |
}catch(error) { | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment