In my reduce loop i'm trying to get two arrays from one.I have async logic inside iteration and I get an error as u can see because I've got promise in result on the third iteration and in broke my script. Here i attach my code to show how i do it!
const {
readyScoreRequests,
remainingScores,
} = await scoreRequests.reduce(async (result, score) => {
const { profile } = score;
console.log('result', result);
const importedScore = score.scoreId ? await importedScoreService.findOne({
where: { id: score.scoreId },
}) : null;
const scoreDate = importedScore ? moment(importedScore.createdOn).format('MM/DD/YYYY') : 'New Score';
const scoreInfo = {
status: score.status.charAt(0).toUpperCase() + score.status.slice(1),
scoreDate,
name: profile ? profile.name : null,
email: score.companyEmail ? score.companyEmail : null,
city: profile ? profile.city : null,
state: profile ? profile.state : null,
logo: profile ? profile.logo : null,
};
if (score.status === 'ready') {
result.readyScoreRequests.push(scoreInfo);
return result;
}
result.remainingScores.push(scoreInfo);
return result;
}, { readyScoreRequests: [], remainingScores: [] });