Skip to content

Commit

Permalink
feat: add filtering by vote choice
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 14, 2023
1 parent 37ce0a0 commit b1cf3ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/graphql/operations/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function query(parent, args, context?, info?) {
vp_state: 'string'
};
const whereQuery = buildWhereQuery(fields, 'v', where);
const queryStr = whereQuery.query;
let queryStr = whereQuery.query;
const params: any[] = whereQuery.params;

let orderBy = args.orderBy || 'created';
Expand All @@ -36,6 +36,12 @@ async function query(parent, args, context?, info?) {

let votes: any[] = [];

if (where.choice_in) {
queryStr +=
' AND JSON_OVERLAPS(JSON_KEYS(choice), JSON_ARRAY(?)) OR JSON_OVERLAPS(choice, JSON_ARRAY(?)) OR choice = ?';
params.push(where.choice_in, where.choice_in, where.choice_in);
}

const query = `
SELECT v.* FROM votes v
WHERE 1 = 1 ${queryStr}
Expand Down
1 change: 1 addition & 0 deletions src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ input VoteWhere {
vp_lte: Float
vp_state: String
vp_state_in: [String]
choice_in: [String]
}

input AliasWhere {
Expand Down

0 comments on commit b1cf3ad

Please sign in to comment.