Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
Using returned async data

So I have an async function that goes like this:

async func1 (file, formData) {

    const id = await API.createCertificate(formData) // this returns the id of the newly created certificate

    const updatePayload = {
      id: id.data.data._id // mongo object id
      fileBuffer: file,
      type: 'certificate'
     }

    await API.attachFile(updatePayload) //attaches file to the newly created object

}

If I console log the id without making the payload it seems to display the right data

    async func1 (file, formData) {      
       const id = await API.createCertificate(formData) // this returns the id of the newly created certificate
       console.log('idContent',id) //this works and it displays all the right data      
    }

However, once I create the 'updatePayload' it throws an error at the id assignment saying cannot access 'data' which I don't get, await is supposed to wait for the promise to resolve before moving right? or am I missing something?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda