@@ -97,6 +97,24 @@ async function updateProposalScores(proposalId: string, scores: any, votes: numb
97
97
] ) ;
98
98
}
99
99
100
+ async function updateProposalScoresValue ( proposalId : string ) {
101
+ const [ proposal ] = await db . queryAsync (
102
+ 'SELECT vp_value_by_strategy, scores_by_strategy FROM proposals WHERE id = ? LIMIT 1;' ,
103
+ [ proposalId ]
104
+ ) ;
105
+ const scoresByStrategy : number [ ] [ ] = JSON . parse ( proposal . scores_by_strategy ) ;
106
+ const vpValueByStrategy : number [ ] = JSON . parse ( proposal . vp_value_by_strategy ) ;
107
+
108
+ const score_total_value =
109
+ scoresByStrategy [ 0 ]
110
+ ?. map ( ( _ , index ) => scoresByStrategy . reduce ( ( sum , array ) => sum + array [ index ] , 0 ) )
111
+ ?. map ( ( value , index ) => value * vpValueByStrategy [ index ] )
112
+ ?. reduce ( ( sum , value ) => sum + value , 0 ) || 0 ;
113
+
114
+ const query = 'UPDATE proposals SET scores_total_value = ? WHERE id = ? LIMIT 1;' ;
115
+ await db . queryAsync ( query , [ score_total_value , proposalId ] ) ;
116
+ }
117
+
100
118
const pendingRequests = { } ;
101
119
102
120
export async function updateProposalAndVotes ( proposalId : string , force = false ) {
@@ -186,6 +204,9 @@ export async function updateProposalAndVotes(proposalId: string, force = false)
186
204
) ;
187
205
188
206
delete pendingRequests [ proposalId ] ;
207
+
208
+ await updateProposalScoresValue ( proposalId ) ;
209
+
189
210
return true ;
190
211
} catch ( e ) {
191
212
delete pendingRequests [ proposalId ] ;
0 commit comments