0
Eae guys I’m having a problem, I get several objects where I mapped them, make an external query using the Axios and save your return. Let’s go to code:
let savedClients = Object.entries(documents).map(personDocument => {
let [person, document] = personDocument
documentFormated = document
documentNumbers = document.replace(/\D/g, '')
return ConsultDocuments.getResponse(documentNumbers).then(resultScore => { // Chamando o axios
const info = { ...resultScore }
return Save.saveClient(info)
})
})
Promise.all(savedClients).then(results => {
console.log(results) // Vem só o ultimo objeto salvo varias vezes
})
poblema is that it performs the entire map first, then queries with the last result several times (the total of documents passed)
This code is a legacy and using async/await does not work (seriously, I wouldn’t even be here)
I’ve tried N forms, and with the Q library, it does in the right order but does not wait for the Xios, the results come all with pending
Thanks.
Can inform the contents of the variable
documents
?– Sorack
{ name: Cpf } example, { fulano : 12312312312398 }
– Develop_SP