Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 3bd85ab

Browse files
committed
adding in member location and escaping member handles
1 parent 8b1d997 commit 3bd85ab

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

group-members-with-skills.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
*/
1818

1919
//require('dotenv').config()
20-
const axios = require('axios')
20+
const _ = require('lodash')
2121
const config = require('config')
2222
const { argv } = require('yargs')
23+
const axios = require('axios')
2324
const m2mAuth = require('tc-core-library-js').auth.m2m
24-
const _ = require('lodash')
25+
const qs = require('querystring');
2526
const { parse } = require('json2csv')
2627
const fs = require('fs')
2728

@@ -135,7 +136,7 @@ async function getMembersInGroup (groupId) {
135136
* Returns the member handle for the member id
136137
* @param {Number} memberId The member id
137138
*/
138-
async function getMemberHandle (memberId) {
139+
async function getMemberRecord (memberId) {
139140
const token = await getM2Mtoken()
140141

141142
try {
@@ -159,12 +160,37 @@ async function getMemberHandle (memberId) {
159160
}
160161
}
161162

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+
162188
/**
163189
* Returns the member's skills
164190
* @param {String} handle The member's handle
165191
*/
166192
async function getMemberSkills (handle) {
167-
const url = `${config.MEMBERS_API_URL}/${handle}/skills`
193+
const url = `${config.MEMBERS_API_URL}/${qs.escape(handle)}/skills`
168194

169195
const token = await getM2Mtoken()
170196

@@ -204,7 +230,7 @@ async function getMemberSkills (handle) {
204230
* @param {Array} data Array of objects
205231
*/
206232
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']
208234

209235
try {
210236
const csv = parse(data, { fields: columns })
@@ -262,7 +288,7 @@ async function start () {
262288
//const memberIds = [8547899]
263289

264290
for (let i = 0; i < memberIds.length; i++) {
265-
const user = await getMemberHandle(memberIds[i])
291+
const user = await getMemberRecord(memberIds[i])
266292
console.log(`pushing '${user.handle}' into stack`)
267293
users.push(user)
268294
console.log(`throttling call for ${config.SLEEP_LENGTH}s`)
@@ -273,6 +299,7 @@ async function start () {
273299

274300
for (let i = 0; i < users.length; i++) {
275301
const handle = users[i].handle
302+
const location = await getMemberLocation(handle)
276303
const skills = await getMemberSkills(handle)
277304

278305
if (skills.length === 0) {
@@ -283,9 +310,13 @@ async function start () {
283310
for (let j = 0; j < skills.length; j++) {
284311
usersWithSkills.push({
285312
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",
289320
skillProviderName,
290321
skillName: skills[j].name,
291322
metricValue: '' + skills[j].score

0 commit comments

Comments
 (0)