17
17
*/
18
18
19
19
//require('dotenv').config()
20
- const axios = require ( 'axios ' )
20
+ const _ = require ( 'lodash ' )
21
21
const config = require ( 'config' )
22
22
const { argv } = require ( 'yargs' )
23
+ const axios = require ( 'axios' )
23
24
const m2mAuth = require ( 'tc-core-library-js' ) . auth . m2m
24
- const _ = require ( 'lodash' )
25
+ const qs = require ( 'querystring' ) ;
25
26
const { parse } = require ( 'json2csv' )
26
27
const fs = require ( 'fs' )
27
28
@@ -135,7 +136,7 @@ async function getMembersInGroup (groupId) {
135
136
* Returns the member handle for the member id
136
137
* @param {Number } memberId The member id
137
138
*/
138
- async function getMemberHandle ( memberId ) {
139
+ async function getMemberRecord ( memberId ) {
139
140
const token = await getM2Mtoken ( )
140
141
141
142
try {
@@ -159,12 +160,37 @@ async function getMemberHandle (memberId) {
159
160
}
160
161
}
161
162
163
+ /**
164
+ * Returns the member location for the member handle
165
+ * @param {String } handle The member handle
166
+ */
167
+ async function getMemberLocation ( handle ) {
168
+ const token = await getM2Mtoken ( )
169
+
170
+ try {
171
+ const res = await axios . get ( `${ config . MEMBERS_API_URL } /${ qs . escape ( handle ) } ` , {
172
+ headers : {
173
+ Authorization : `Bearer ${ token } `
174
+ }
175
+ } )
176
+ console . log ( res . data )
177
+ const location = _ . pick ( _ . get ( res , 'data[0]' , { } ) , [ 'homeCountryCode' , 'competitionCountryCode' ] )
178
+
179
+ return location . homeCountryCode || location . competitionCountryCode || 'n/a'
180
+ } catch ( error ) {
181
+ console . log ( `Error getting the member location for member with handle: ${ handle } ` )
182
+ console . log ( error )
183
+
184
+ throw error
185
+ }
186
+ }
187
+
162
188
/**
163
189
* Returns the member's skills
164
190
* @param {String } handle The member's handle
165
191
*/
166
192
async function getMemberSkills ( handle ) {
167
- const url = `${ config . MEMBERS_API_URL } /${ handle } /skills`
193
+ const url = `${ config . MEMBERS_API_URL } /${ qs . escape ( handle ) } /skills`
168
194
169
195
const token = await getM2Mtoken ( )
170
196
@@ -204,7 +230,7 @@ async function getMemberSkills (handle) {
204
230
* @param {Array } data Array of objects
205
231
*/
206
232
async function getCSV ( data ) {
207
- const columns = [ 'handle' , 'firstName' , 'lastName' , 'email' , 'skillProviderName' , 'skillName' , 'metricValue' ]
233
+ const columns = [ 'handle' , 'firstName' , 'lastName' , 'email' , 'isAvailable' , 'company' , 'location' , 'title' , ' skillProviderName', 'skillName' , 'metricValue' ]
208
234
209
235
try {
210
236
const csv = parse ( data , { fields : columns } )
@@ -262,7 +288,7 @@ async function start () {
262
288
//const memberIds = [8547899]
263
289
264
290
for ( let i = 0 ; i < memberIds . length ; i ++ ) {
265
- const user = await getMemberHandle ( memberIds [ i ] )
291
+ const user = await getMemberRecord ( memberIds [ i ] )
266
292
console . log ( `pushing '${ user . handle } ' into stack` )
267
293
users . push ( user )
268
294
console . log ( `throttling call for ${ config . SLEEP_LENGTH } s` )
@@ -273,6 +299,7 @@ async function start () {
273
299
274
300
for ( let i = 0 ; i < users . length ; i ++ ) {
275
301
const handle = users [ i ] . handle
302
+ const location = await getMemberLocation ( handle )
276
303
const skills = await getMemberSkills ( handle )
277
304
278
305
if ( skills . length === 0 ) {
@@ -283,9 +310,13 @@ async function start () {
283
310
for ( let j = 0 ; j < skills . length ; j ++ ) {
284
311
usersWithSkills . push ( {
285
312
handle,
286
- firstName,
287
- lastName,
288
- email,
313
+ firstName : users [ i ] . firstName ,
314
+ lastName : users [ i ] . lastName ,
315
+ email : users [ i ] . email ,
316
+ isAvailable : "true" ,
317
+ company : "Topcoder" ,
318
+ location,
319
+ title : "Member" ,
289
320
skillProviderName,
290
321
skillName : skills [ j ] . name ,
291
322
metricValue : '' + skills [ j ] . score
0 commit comments