File tree 4 files changed +23
-10
lines changed
4 files changed +23
-10
lines changed Original file line number Diff line number Diff line change 31
31
"lint:js" : " ./node_modules/.bin/eslint --ext .js,.jsx ." ,
32
32
"test" : " npm run lint && npm run jest"
33
33
},
34
- "version" : " 1.1.7 " ,
34
+ "version" : " 1.1.8 " ,
35
35
"dependencies" : {
36
36
"auth0-js" : " ^6.8.4" ,
37
37
"config" : " ^3.2.0" ,
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ async function getStatsInit(handle, uuid) {
114
114
* @static
115
115
* @desc Create an action that loads member statistics.
116
116
* @param {String } handle Member handle.
117
- * @param {String } groupIds Group ids.
117
+ * @param {Array<String>| String } groupIds Group ids.
118
118
* @param {String } uuid Operation UUID.
119
119
* @param {String } tokenV3 v3 auth token.
120
120
* @return {Action }
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ function getStatsInit() {}
132
132
* @static
133
133
* @desc Creates an action that loads member's stats.
134
134
* @param {String } handle Member handle.
135
- * @param {String } groupIds Group ids.
135
+ * @param {Array<String>| String } groupIds Group ids.
136
136
* @return {Action }
137
137
*/
138
138
function getStatsDone ( handle , groupIds ) {
Original file line number Diff line number Diff line change @@ -83,17 +83,30 @@ class MembersService {
83
83
/**
84
84
* Gets member statistics.
85
85
* @param {String } handle
86
- * @param {String } groupIds
86
+ * @param {Array<String>| String } groupIds
87
87
* @return {Promise } Resolves to the stats object.
88
88
*/
89
89
async getStats ( handle , groupIds ) {
90
- let res ;
91
- if ( groupIds ) {
92
- res = await this . private . api . get ( `/members/${ handle } /stats?groupIds=${ groupIds } ` ) ;
93
- } else {
94
- res = await this . private . api . get ( `/members/${ handle } /stats` ) ;
90
+ if ( ! groupIds || ( _ . isArray ( groupIds ) && groupIds . length === 0 ) ) {
91
+ const res = await this . private . api . get ( `/members/${ handle } /stats` ) ;
92
+ return getApiResponsePayload ( res ) ;
95
93
}
96
- return getApiResponsePayload ( res ) ;
94
+
95
+ const groupIdsArray = _ . isArray ( groupIds ) ? groupIds : _ . split ( groupIds , ',' ) ;
96
+ const groupIdChunks = _ . chunk ( groupIdsArray , 50 ) ;
97
+
98
+ const getStatRequests = _ . map ( groupIdChunks , async ( groupIdChunk ) => {
99
+ const res = await this . private . api . get ( `/members/${ handle } /stats?groupIds=${ _ . join ( groupIdChunk ) } ` ) ;
100
+ return getApiResponsePayload ( res , false ) ;
101
+ } ) ;
102
+ const results = await Promise . all ( getStatRequests ) ;
103
+
104
+ return _ . uniqBy (
105
+ _ . flatten (
106
+ _ . filter ( results , _ . isArray ) ,
107
+ ) ,
108
+ item => item . groupId ,
109
+ ) ;
97
110
}
98
111
99
112
/**
You can’t perform that action at this time.
0 commit comments