我正在尝试计算用户统计信息,使用事件主体中某些值的信息对mysql数据库进行查询。然后使用该数据进行计算,更新数据库中的统计信息。但是,虽然我可以从数据库中看到数据的实例,但无法在以后的函数中使用它,从而导致NaN或未定义。
....
const user = await User.findOrCreate({
raw: true,
where: {
userId: entry.userId
}
})
console.log("1", user)
const UserTotalSubmissions = await Submission.findAll({
raw: true,
where: {
userId: entry.userId
}
})
console.log("2", UserTotalSubmissions)
const getTotalAvailableScore = async () => {
const sum = await UserTotalSubmissions.reduce((a,b) => a.totalScore + b.totalScore)
return sum
}
console.log("3", await getTotalAvailableScore())
const getTotalUserScore = async () => {
const sum = await UserTotalSubmissions.reduce((a,b) => a.score + b.score)
return sum
}
console.log("4", await getTotalUserScore())
....