@@ -76,7 +76,7 @@ async function createChallenge(challenge) {
76
76
} ] ,
77
77
timelineTemplateId : config . DEFAULT_TIMELINE_TEMPLATE_ID ,
78
78
projectId : challenge . projectId ,
79
- tags : challenge . tags ,
79
+ tags : challenge . tags . map ( ( tag ) => tag . name ) ,
80
80
trackId : config . DEFAULT_TRACK_ID ,
81
81
legacy : {
82
82
pureV5Task : true
@@ -163,6 +163,41 @@ async function activateChallenge(id) {
163
163
}
164
164
}
165
165
166
+ /**
167
+ * Apply skills set to the challenge
168
+ * @param {String } challengeId the challenge id
169
+ * @param {Array<{id: string, name: string}> } tags the list of tags applied to the challenge
170
+ */
171
+ async function applySkillsSetToChallenge ( challengeId , tags ) {
172
+ const apiKey = await getM2Mtoken ( ) ;
173
+ logger . debug ( `Applying skills set to the challenge ${ challengeId } ` ) ;
174
+ const url = `${ config . TC_API_URL } /standardized-skills/work-skills` ;
175
+ const payload = {
176
+ workId : challengeId ,
177
+ workTypeId : config . WORK_TYPE_ID ,
178
+ skillIds : tags . map ( ( tag ) => tag . id )
179
+ } ;
180
+ const params = {
181
+ headers : {
182
+ authorization : `Bearer ${ apiKey } ` ,
183
+ 'Content-Type' : 'application/json'
184
+ }
185
+ } ;
186
+ try {
187
+ const response = await axios . post ( url , payload , params ) ;
188
+ const statusCode = response . status ? response . status : null ;
189
+ loggerFile . info ( `EndPoint: POST /standardized-skills/work-skills,
190
+ POST parameters: ${ circularJSON . stringify ( payload ) } , Status Code:${ statusCode } , Response: ${ circularJSON . stringify ( response . data ) } ` ) ;
191
+ logger . debug ( `Skills set applied successfully to the challenge ${ challengeId } ` ) ;
192
+ return response . data ;
193
+ } catch ( err ) {
194
+ loggerFile . info ( `EndPoint: POST /standardized-skills/work-skills, POST parameters: ${ circularJSON . stringify ( payload ) } , Status Code:null,
195
+ Error: 'Failed to apply skills set to the challenge.', Details: ${ circularJSON . stringify ( err ) } ` ) ;
196
+ logger . error ( `Response Data: ${ JSON . stringify ( err . response . data ) } ` ) ;
197
+ throw errors . convertTopcoderApiError ( err , 'Failed to apply skills set to the challenge.' ) ;
198
+ }
199
+ }
200
+
166
201
/**
167
202
* Get challenge details by id
168
203
* @param {String } id challenge ID
@@ -511,6 +546,7 @@ module.exports = {
511
546
createChallenge,
512
547
updateChallenge,
513
548
activateChallenge,
549
+ applySkillsSetToChallenge,
514
550
closeChallenge,
515
551
getProjectBillingAccountId,
516
552
getTopcoderMemberId,
0 commit comments