@@ -59,22 +59,18 @@ async function createUserInTopcoder (user) {
59
59
/**
60
60
* Creates the user in UBahn api as well as Topcoder's Users api
61
61
* @param {Object } user The user to create
62
+ * @param {String } organizationId The org id to associate the new user with
62
63
*/
63
- async function createUser ( user ) {
64
+ async function createUser ( user , organizationId ) {
64
65
// Create the user in Topcoder
65
66
const topcoderUserId = await createUserInTopcoder ( user )
66
67
67
68
// Create the user in UBahn api
68
69
const ubahnUserId = await createUserInUbahn ( user )
69
70
70
- // Get the topcoder organization
71
- const topcoderOrg = await helper . getUbahnSingleRecord ( '/organizations' , {
72
- name : config . TOPCODER_ORGANIZATION_NAME
73
- } )
74
-
75
71
// Now, proceed to map the topcoder user id with the ubahn user id
76
72
await helper . createUbahnRecord ( `/users/${ ubahnUserId } /externalProfiles` , {
77
- organizationId : topcoderOrg . id ,
73
+ organizationId,
78
74
externalId : topcoderUserId
79
75
} )
80
76
@@ -85,9 +81,10 @@ async function createUser (user) {
85
81
/**
86
82
* Function to get user id
87
83
* @param {Object } user
84
+ * @param {Object } organizationId The org id to associate a new user with
88
85
* @returns {Promise }
89
86
*/
90
- async function getUserId ( user ) {
87
+ async function getUserId ( user , organizationId ) {
91
88
const record = await helper . getUbahnSingleRecord ( '/users' , {
92
89
handle : user . handle
93
90
} , true )
@@ -97,7 +94,7 @@ async function getUserId (user) {
97
94
98
95
// No user found. Should we create the user or treat it as an error?
99
96
if ( config . CREATE_MISSING_USER_FLAG ) {
100
- return createUser ( user )
97
+ return createUser ( user , organizationId )
101
98
} else {
102
99
throw new Error ( `Could not find user with handle ${ user . handle } ` )
103
100
}
@@ -194,11 +191,12 @@ async function createUserAttributes (userId, record) {
194
191
* Function to process record
195
192
* @param {Object } record
196
193
* @param {Array } failedRecord then failed records container
194
+ * @param {String } organizationId The org id to associate a new user with
197
195
* @returns {Promise }
198
196
*/
199
- async function processCreateRecord ( record , failedRecord ) {
197
+ async function processCreateRecord ( record , failedRecord , organizationId ) {
200
198
try {
201
- const userId = await getUserId ( record )
199
+ const userId = await getUserId ( record , organizationId )
202
200
await createUserSkill ( userId , record . skillProviderName , record . skillName , record . skillCertifierId , record . skillCertifiedDate , record . metricValue )
203
201
await createAchievement ( userId , record . achievementsProviderName , record . achievementsCertifierId , record . achievementsCertifiedDate , record . achievementsName , record . achievementsUri )
204
202
await createUserAttributes ( userId , record )
@@ -221,7 +219,7 @@ async function processCreate (message) {
221
219
const records = helper . parseExcel ( file )
222
220
const failedRecord = [ ]
223
221
224
- await Promise . map ( records , record => processCreateRecord ( record , failedRecord ) , { concurrency : config . PROCESS_CONCURRENCY_COUNT } )
222
+ await Promise . map ( records , record => processCreateRecord ( record , failedRecord , message . payload . organizationId ) , { concurrency : config . PROCESS_CONCURRENCY_COUNT } )
225
223
226
224
if ( failedRecord . length > 0 ) {
227
225
await helper . uploadFailedRecord ( failedRecord , message . payload . objectKey )
@@ -247,6 +245,7 @@ processCreate.schema = {
247
245
resource : Joi . string ( ) . required ( ) ,
248
246
objectKey : Joi . string ( ) . required ( ) ,
249
247
status : Joi . string ( ) . required ( ) ,
248
+ organizationId : Joi . string ( ) . required ( ) ,
250
249
id : Joi . id ( )
251
250
} ) . required ( ) . unknown ( true )
252
251
} ) . required ( )
0 commit comments