@@ -24,14 +24,27 @@ import { getObjectId } from './utils';
24
24
import { logError } from '../lib/utils' ;
25
25
import { Credentials } from '../model/credentials' ;
26
26
27
- export function getVotes ( votesColl : Collection , id ?: string | { eventId : string } ) : Observable < Vote [ ] > {
28
- let eventId : any ;
29
- if ( id && typeof id === 'string' ) {
30
- eventId = id ;
31
- } else if ( id ) {
32
- eventId = id [ 'eventId' ] ;
27
+ export function getVotes (
28
+ votesColl : Collection ,
29
+ params ?: string | { eventId : string ; voterId ?: any } ,
30
+ ) : Observable < Vote [ ] > {
31
+ let _eventId : any ;
32
+ if ( params && typeof params === 'string' ) {
33
+ _eventId = params ;
34
+ } else if ( params ) {
35
+ _eventId = params [ 'eventId' ] ;
36
+ }
37
+ let selector : any = _eventId
38
+ ? { cancelled : { $exists : false } , eventId : _eventId }
39
+ : { cancelled : { $exists : false } } ;
40
+ if ( params && params [ 'voterId' ] ) {
41
+ const upperCaseVoterId : any = { } ;
42
+ const voterId = params [ 'voterId' ] ;
43
+ for ( const key in voterId ) {
44
+ upperCaseVoterId [ key ] = voterId [ key ] . toUpperCase ( ) ;
45
+ }
46
+ selector . voterId = upperCaseVoterId ;
33
47
}
34
- const selector = eventId ? { cancelled : { $exists : false } , eventId } : { cancelled : { $exists : false } } ;
35
48
return findObs ( votesColl , selector ) . pipe ( toArray ( ) ) ;
36
49
}
37
50
export function getAllVotes ( votesColl : Collection ) : Observable < Vote [ ] > {
@@ -122,10 +135,16 @@ function voterIdToUpperCase(voterId: { firstName: string; lastName: string } | C
122
135
lastName : voterId [ 'lastName' ] . toUpperCase ( ) . trim ( ) ,
123
136
} ;
124
137
} else {
125
- resp = {
126
- nickname : voterId [ 'nickname' ] ? voterId [ 'nickname' ] . toUpperCase ( ) . trim ( ) : '' ,
127
- userId : voterId [ 'userId' ] ? voterId [ 'userId' ] . toUpperCase ( ) . trim ( ) : '' ,
128
- } ;
138
+ if ( voterId [ 'nickname' ] ) {
139
+ resp = {
140
+ nickname : voterId [ 'nickname' ] . toUpperCase ( ) . trim ( ) ,
141
+ } ;
142
+ }
143
+ if ( voterId [ 'userId' ] ) {
144
+ resp = {
145
+ userId : voterId [ 'userId' ] . toUpperCase ( ) . trim ( ) ,
146
+ } ;
147
+ }
129
148
}
130
149
return resp ;
131
150
}
0 commit comments