Skip to content

Commit

Permalink
update feedbackChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Jan 10, 2019
1 parent 09975e6 commit 3cc2db4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions functions/src/lib/feedbacks/changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ export const feedbackChanged = FEEDBACKS_FUNC_REF

feedbacks.forEach(feedback => {
const {roomId, ratings} = feedback.data()
if (Array.isArray(rooms[roomId])) {
rooms[roomId].push(getRatingAverage(ratings))
} else {
rooms[roomId] = [(getRatingAverage(ratings))]
}
roomId.forEach(r => {
if (Array.isArray(rooms[r])) {
rooms[r].push(getRatingAverage(ratings))
} else {
rooms[r] = [(getRatingAverage(ratings))]
}
})
})

const averages = {}
Object.entries(rooms).forEach(([roomId, room]) =>
averages[roomId] = room.reduce((acc, rating) => acc + rating) / room.length
)
Object.entries(rooms).forEach(([roomId, room]) => {
roomId.forEach(roomId => {
averages[roomId] = room.reduce((acc, rating) => acc + rating) / room.length
})
})

await FEEDBACKS_DB_REF.set(averages)

Expand Down

0 comments on commit 3cc2db4

Please sign in to comment.