I´m currently trying to create an array that searches in my database and then returns a response to frontend, but the array always returns null, is there a way to prevent the response to go before the map function is completed?
My code:
const result = await Database.raw(sqlResult)
const data = await result.rows.map((element, index) => {
this.getNomFun(result.rows[index].numcad)
.then((response) => {
const dataFun = response.toJSON()
return {
numcad: dataFun[0].numcad,
nomfun: dataFun[0].nomfun,
titred: dataFun[0].titred,
numcpf: dataFun[0].numcpf,
numcid: dataFun[0].numcid,
datnas: dataFun[0].datnas,
codccu: dataFun[0].codccu,
nomloc: dataFun[0].nomloc,
sms_documents_id: result.rows[index].sms_documents_id,
register_date: result.rows[index].register_date,
expiration_date: result.rows[index].expiration_date,
name: result.rows[index].name,
description: result.rows[index].description,
time_period: result.rows[index].time_period,
}
}).catch((err) => console.log(`err ${err}`))
})
return data