I'm trying to create a new array object in my Promise
function and I'm also trying to add user parameters from the getUser
function.
I'm struggling to get the data into the array.
Could someone give me an example of how I could implement this?
Thanks.
var results_array = [];
return callHistory(76).then((result)=>{
_.map(result, (item, index) => {
var obj = JSON.parse(item.params);
results_array[index] = {
id: item.id,
status: item.status,
timestamp: item.timestamp,
from_id:obj.from_id,
to_id: obj.to_id,
conference: obj.conference,
to:"",
from:getUser(10)
};
});
res.json({
status: 1,
result: results_array
})
//return results_array;
})
function getUser(id){
return new Promise(function (resolve, reject) {
connection.query(`SELECT * FROM members WHERE id = ${id} `, function (error, results, fields) {
if (error) reject(error);
return resolve(results);
});
});
}