Skip to content

Commit b8cb030

Browse files
authored
feat: add scores_total_value and vp_value_by_strategy to proposals GraphQL operation (#1025)
* feat: add scores_total_value and vp_value_by_strategy to proposals GraphQL operation * fix: update orderBy logic to dynamically include valid fields
1 parent 921fb2a commit b8cb030

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/graphql/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ export function formatProposal(proposal) {
440440
proposal.plugins = jsonParse(proposal.plugins, {});
441441
proposal.scores = jsonParse(proposal.scores, []);
442442
proposal.scores_by_strategy = jsonParse(proposal.scores_by_strategy, []);
443+
proposal.vp_value_by_strategy = jsonParse(proposal.vp_value_by_strategy, []);
443444
let proposalState = 'pending';
444445
const ts = parseInt((Date.now() / 1e3).toFixed());
445446
if (ts > proposal.start) proposalState = 'active';

src/graphql/operations/proposals.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default async function (parent, args) {
2121
end: 'number',
2222
type: 'string',
2323
scores_state: 'string',
24-
votes: 'number'
24+
votes: 'number',
25+
scores_total_value: 'number'
2526
};
2627
const whereQuery = buildWhereQuery(fields, 'p', where);
2728
let queryStr = whereQuery.query;
@@ -78,10 +79,13 @@ export default async function (parent, args) {
7879
params.push(JSON.stringify(where.labels_in));
7980
}
8081

82+
const orderByFields = Object.entries(fields)
83+
.filter(field => field[1] === 'number')
84+
.map(field => field[0]);
85+
8186
let orderBy = args.orderBy || 'created';
8287
let orderDirection = args.orderDirection || 'desc';
83-
if (!['created', 'start', 'end', 'votes'].includes(orderBy))
84-
orderBy = 'created';
88+
if (!orderByFields.includes(orderBy)) orderBy = 'created';
8589
orderBy = `p.${orderBy}`;
8690
orderDirection = orderDirection.toUpperCase();
8791
if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC';

src/graphql/schema.gql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ input ProposalWhere {
231231
votes_gte: Int,
232232
votes_lt: Int,
233233
votes_lte: Int,
234+
scores_total_value: Float
235+
scores_total_value_in: [Float]
236+
scores_total_value_gt: Float
237+
scores_total_value_gte: Float
238+
scores_total_value_lt: Float
239+
scores_total_value_lte: Float
234240
}
235241

236242
input VoteWhere {
@@ -510,6 +516,8 @@ type Proposal {
510516
scores_state: String
511517
scores_total: Float
512518
scores_updated: Int
519+
scores_total_value: Float
520+
vp_value_by_strategy: Any
513521
votes: Int
514522
flagged: Boolean
515523
flagCode: Int

0 commit comments

Comments
 (0)