Skip to content

Commit

Permalink
rename + fix in query (we were ignoring ideas with 0 votes before)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkvon committed Apr 4, 2018
1 parent 30a11ec commit 6ebc170
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions models/idea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,15 @@ class Idea extends Model {
static async findHighlyVoted(voteSumBottomLimit, { offset, limit }) {
const query = `
FOR idea IN ideas
FOR vote IN votes
FILTER idea._id == vote._to
// group by idea id
COLLECT id = idea
LET ideaVotes = (FOR vote IN votes FILTER idea._id == vote._to RETURN vote)
// get sum of each idea's votes values
AGGREGATE voteSum = SUM(vote.value)
LET voteSum = SUM(ideaVotes[*].value)
// set bottom limit of voteSum
FILTER voteSum >= @voteSumBottomLimit
// find creator
LET c = (DOCUMENT(id.creator))
LET c = (DOCUMENT(idea.creator))
LET creator = MERGE(KEEP(c, 'username'), c.profile)
LET ideaOut = MERGE(KEEP(id, 'title', 'detail', 'created'), { id: id._key}, { creator }, { voteSum })
LET ideaOut = MERGE(KEEP(idea, 'title', 'detail', 'created'), { id: idea._key}, { creator }, { voteSum })
// sort by amount of votes
SORT ideaOut.voteSum DESC, ideaOut.created DESC
Expand Down

0 comments on commit 6ebc170

Please sign in to comment.