File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -45,17 +45,24 @@ function getVotes(client) {
45
45
if ( err ) {
46
46
console . error ( "Error performing query: " + err ) ;
47
47
} else {
48
- var data = result . rows . reduce ( function ( obj , row ) {
49
- obj [ row . vote ] = row . count ;
50
- return obj ;
51
- } , { } ) ;
52
- io . sockets . emit ( "scores" , JSON . stringify ( data ) ) ;
48
+ var votes = collectVotesFromResult ( result ) ;
49
+ io . sockets . emit ( "scores" , JSON . stringify ( votes ) ) ;
53
50
}
54
51
55
52
setTimeout ( function ( ) { getVotes ( client ) } , 1000 ) ;
56
53
} ) ;
57
54
}
58
55
56
+ function collectVotesFromResult ( result ) {
57
+ var votes = { a : 0 , b : 0 } ;
58
+
59
+ result . rows . forEach ( function ( row ) {
60
+ votes [ row . vote ] = parseInt ( row . count ) ;
61
+ } ) ;
62
+
63
+ return votes ;
64
+ }
65
+
59
66
app . use ( cookieParser ( ) ) ;
60
67
app . use ( bodyParser ( ) ) ;
61
68
app . use ( methodOverride ( 'X-HTTP-Method-Override' ) ) ;
You can’t perform that action at this time.
0 commit comments