Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda