@@ -14,8 +14,14 @@ const apiRaces = (variable, body) => {
14
14
} ) ;
15
15
} ;
16
16
const apiCandidates = ( variable , body ) => {
17
- var races = variable ? body . races . map ( x => x . candidates . filter ( y => y . candidate_code == parseInt ( variable ) ) ) : body . races ;
18
- return races . reduce ( ( acc , val ) => acc . concat ( val . candidates . map ( c => {
17
+ var races = variable ? body . races . map ( x => {
18
+ if ( x . candidates . filter ( y => y . candidate_code == parseInt ( variable ) ) ) {
19
+ return x ;
20
+ }
21
+
22
+
23
+ } ) : body . races ;
24
+ return races . reduce ( ( acc , val ) => acc . concat ( val . candidates . filter ( y => variable ? y . candidate_code == parseInt ( variable ) : y . candidate_code ) . map ( c => {
19
25
return {
20
26
21
27
candidate_code : c . candidate_code ,
@@ -27,17 +33,28 @@ const apiCandidates = (variable, body) => {
27
33
} ) ) , [ ] ) ;
28
34
} ;
29
35
const apiCounties = ( variable , body ) => {
30
- var races = variable ? body . races . map ( x => x . counties . filter ( y => y . county_name === variable ) ) : body . races ;
31
- return races . reduce ( ( acc , val ) => acc . concat ( val . counties . map ( c => {
32
- return {
33
- county_code : c . county_code ,
34
- party_stratum_name : c . party_stratum_name ,
35
- registered : c . registered ,
36
- total_vote : c . total_vote ,
37
- fips_code : c . fips_code ,
38
- race_id : val . race_id
39
- } ;
40
- } ) ) , [ ] ) ;
36
+ var races = variable ? body . races . map ( x => {
37
+ if ( x . counties . filter ( y => y . county_name === variable ) ) {
38
+ return x ;
39
+ }
40
+
41
+ } ) : body . races ;
42
+
43
+ console . log ( races ) ;
44
+ return races . reduce ( ( acc , val ) =>
45
+ acc . concat ( val . counties . filter ( x => variable ? x . county_name === variable : x . county_name ) . map ( c =>
46
+
47
+
48
+ {
49
+ return {
50
+ county_code : c . county_code ,
51
+ party_stratum_name : c . party_stratum_name ,
52
+ registered : c . registered ,
53
+ total_vote : c . total_vote ,
54
+ fips_code : c . fips_code ,
55
+ race_id : val . race_id
56
+ } ;
57
+ } ) ) , [ ] ) ;
41
58
42
59
} ;
43
60
module . exports = {
0 commit comments