1- import { Candidate } from 'Models' ;
1+ import { Candidate } from 'Models' ;
22var joinjs = require ( 'join-js' ) . default ;
3- import { List } from 'typed-immutable' ;
3+ import { List } from 'typed-immutable' ;
44import _ from 'lodash' ;
55import moment from 'moment' ;
66
@@ -10,13 +10,13 @@ const resultMaps = [
1010 mapId : 'candidateMap' ,
1111 idProperty : 'ID' ,
1212 // properties: ['FULL_NAME', 'DES','OCCUPATION','NIC', 'DATE_OF_BIRTH', 'GENDER','ADDRESS', 'NOMINATION_ID']
13- properties : [ 'CONFIG_ID' , 'KEY_NAME' , 'VALUE' ]
13+ properties : [ 'CONFIG_ID' , 'KEY_NAME' , 'VALUE' ]
1414 }
1515] ;
1616
1717
1818const mapToCandidateModel = ( candidates ) => {
19- console . log ( 'candidates' , candidates ) ;
19+ console . log ( 'candidates' , candidates ) ;
2020 var groupedCandidates = _ . groupBy ( candidates , 'CANDIDATE_ID' ) ;
2121 var expected = _ . map ( groupedCandidates , function ( candidateProperties ) {
2222 var orderedProps = [ ] ;
@@ -27,40 +27,41 @@ const mapToCandidateModel = (candidates) => {
2727 } ) ;
2828 orderedProps = _ . sortBy ( orderedProps , 'CANDIDATE_CONFIG_ID' ) ;
2929
30- var candidateInfoMap = { CANDIDATE_ID :id } ;
30+ var candidateInfoMap = { CANDIDATE_ID : id } ;
3131 _ . each ( orderedProps , function ( property ) {
32- if ( property . CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH' ) {
32+ if ( property . CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH' ) {
3333 candidateInfoMap [ property . CANDIDATE_KEY_NAME ] = moment ( new Date ( parseInt ( property . CANDIDATE_VALUE ) ) ) . format ( 'YYYY-MM-DD' ) ;
34- } else {
34+ } else {
3535 candidateInfoMap [ property . CANDIDATE_KEY_NAME ] = property . CANDIDATE_VALUE ;
3636 }
3737 } ) ;
38-
38+
3939 return candidateInfoMap ;
4040 } ) ;
41- console . log ( 'expected' , expected ) ;
41+ console . log ( 'expected' , expected ) ;
4242 return expected ;
4343 // const mappedCandidates = joinjs.map(candidates, resultMaps, 'candidateMap', 'CANDIDATE_');
44- // const mappedCandidates = expected;
44+ // const mappedCandidates = expected;
45+
46+ // console.log("mappedCandidatesmappedCandidatesmappedCandidates",mappedCandidates);
47+ // return _.reduce(mappedCandidates, function(result, candidate) {
4548
46- // console.log("mappedCandidatesmappedCandidatesmappedCandidates",mappedCandidates);
47- // return _.reduce(mappedCandidates, function(result, candidate) {
48-
49- // return result.push({
50- // "id": candidate.ID,
51- // "configId": candidate.CONFIG_ID,
52- // "keyName": candidate.KEY_NAME,
53- // "value": candidate.VALUE
49+ // return result.push({
50+ // "id": candidate.ID,
51+ // "configId": candidate.CONFIG_ID,
52+ // "keyName": candidate.KEY_NAME,
53+ // "value": candidate.VALUE
5454
55- // });
56- // },List(Candidate)());
55+ // });
56+ // },List(Candidate)());
5757
5858
5959} ;
6060
61- const mapToPartyCandidateModel = ( candidates , party_list , division_list ) => {
62- console . log ( 'candidates' , candidates ) ;
61+ const mapToPartyCandidateModel = ( candidates , party_list , division_list ) => {
62+ console . log ( 'party_list' , party_list ) ;
6363 var groupedCandidates = _ . groupBy ( candidates , 'CANDIDATE_ID' ) ;
64+ console . log ( 'division_list' , division_list ) ;
6465 var expected = _ . map ( groupedCandidates , function ( candidateProperties ) {
6566 var orderedProps = [ ] ;
6667 var id = "" ;
@@ -70,33 +71,35 @@ const mapToPartyCandidateModel = (candidates,party_list,division_list) => {
7071 } ) ;
7172 orderedProps = _ . sortBy ( orderedProps , 'CANDIDATE_CONFIG_ID' ) ;
7273
73- var candidateInfoMap = { CANDIDATE_ID :id } ;
74+ var candidateInfoMap = { CANDIDATE_ID : id } ;
7475 _ . each ( orderedProps , function ( property ) {
75- if ( property . CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH' ) {
76+ if ( property . CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH' ) {
7677 candidateInfoMap [ property . CANDIDATE_KEY_NAME ] = moment ( new Date ( parseInt ( property . CANDIDATE_VALUE ) ) ) . format ( 'YYYY-MM-DD' ) ;
77- } else {
78+ } else {
7879 candidateInfoMap [ property . CANDIDATE_KEY_NAME ] = property . CANDIDATE_VALUE ;
7980 }
8081 } ) ;
81-
82- return candidateInfoMap ;
83- } ) ;
84-
85- const expectedWithParty = party_list . map ( item => {
86- //check and change the team_id variable name after finishing the party list endpoint
87- const item2 = expected . find ( o => o . team_id === item . team_id ) ;
88- return { ...item , ...item2 } ;
89- } ) ;
9082
91- const expectedWithPartyDivision = division_list . map ( item => {
92- //check and change the vivision_id variable name after finishing the division list endpoint
93- const item2 = expectedWithParty . find ( o => o . division_id === item . division_id ) ;
94- return { ...item , ...item2 } ;
83+ return candidateInfoMap ;
9584 } ) ;
9685
86+ if ( party_list ) {
87+ const expectedWithParty = party_list . map ( item => {
88+ //check and change the team_id variable name after finishing the party list endpoint
89+ const item2 = expected . find ( o => o . team_id === item . team_id ) ;
90+ return { ...item , ...item2 } ;
91+ } ) ;
92+ }
93+ if ( division_list ) {
94+ const expectedWithPartyDivision = division_list . map ( item => {
95+ //check and change the vivision_id variable name after finishing the division list endpoint
96+ const item2 = expectedWithParty . find ( o => o . division_id === item . division_id ) ;
97+ return { ...item , ...item2 } ;
98+ } ) ;
99+ }
97100
98- console . log ( 'expected' , expected ) ;
99- return expectedWithPartyDivision ;
101+ console . log ( 'expected' , expected ) ;
102+ return expected ;
100103} ;
101104
102105export default {
0 commit comments