Я пытаюсь использовать forEach и map внутри асинхронной функции, но это ничего не возвращает.
Вот мой код:
async function test(){
const sqsMessages = [{"eventname":"\\core\\event\\user_list_viewed","component":"core","action":"viewed","target":"user_list","objecttable":"course","objectid":"2","crud":"r","edulevel":0,"contextid":25,"contextlevel":50,"contextinstanceid":"2","userid":"2","courseid":"2","relateduserid":null,"anonymous":0,"other":"{\"courseshortname\":\"324234\",\"coursefullname\":\"Teste\"}","timecreated":1572957245,"origin":"web","ip":"127.0.0.1","realuserid":null}];
const queryValues = sqsMessages.forEach( logs => {
return `(null,${ [
...Object.values(logs).map(async val => {
if (typeof val === 'number') {
return await val;
}
if (typeof val === 'string') {
return await `'${val}'`;
}
return await `${val}`;
}),
].join(',')})`;
});
return queryValues;
}
Когда я пытаюсь пообещать, я получил эту ошибку:
async function test(){
const sqsMessages = [{"eventname":"\\core\\event\\user_list_viewed","component":"core","action":"viewed","target":"user_list","objecttable":"course","objectid":"2","crud":"r","edulevel":0,"contextid":25,"contextlevel":50,"contextinstanceid":"2","userid":"2","courseid":"2","relateduserid":null,"anonymous":0,"other":"{\"courseshortname\":\"324234\",\"coursefullname\":\"Teste\"}","timecreated":1572957245,"origin":"web","ip":"127.0.0.1","realuserid":null}];
const queryValues = sqsMessages.forEach( logs => {
return `(null,${ [
...Object.values(logs).map(async val => {
if (typeof val === 'number') {
return await val;
}
if (typeof val === 'string') {
return await `'${val}'`;
}
return await `${val}`;
}),
].join(',')})`;
});
const resultado = await Promise.all(queryValues);
return resultado;
}
TypeError: undefined is not iterable
что я делаю не так?