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?