I have a problem and I can't deal with it.
- Downloading data from the database
- I create loops with data from the database
- The records contain the key to download the photo
- I'm downloading pictures from getImage async
- if there is no photo I put: 'none'
- by doing res.json 'datalist' no records with a photo are returned
sqlRequest.query(sqlQuery, function(err, data, req) {
if (err) {
console.log(err);
res.send(err);
} else {
const datalist = [];
data.recordset.forEach(async element => {
if (element.ImageFirst != null) {
const get_Image = await getImage(element.KEY_BUCKET);
const lipst_p = {
id: element.ID,
image: get_Image.Body,
}
datalista.push(lipst_p);
} else {
const lipst_p = {
id: element.ID,
image: 'none',
}
datalista.push(lipst_p);
}
});
res.json({
data: datalist
});
}
});
If I do the console.log section below :
if (element.ImageFirst != null) {
const get_Image = await getImage(element.KEY_BUCKET);
const lipst_p = {
id: element.ID,
image: get_Image.Body,
}
console.log(lipst_p);
datalista.push(lipst_p);
}
gets all the correct values to console.log