Skip to content

Commit fd7577c

Browse files
author
liuliquan
authored
Merge pull request #701 from topcoder-platform/dev
CORE-112 get skills in chunk batch
2 parents 8c28084 + 80e3284 commit fd7577c

File tree

2 files changed

+118
-9
lines changed

2 files changed

+118
-9
lines changed

docs/swagger.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ paths:
5858
produces:
5959
- application/json
6060
parameters:
61+
- $ref: "#/parameters/app-version"
6162
- $ref: "#/parameters/page"
6263
- $ref: "#/parameters/perPage"
6364
- name: id
@@ -472,6 +473,7 @@ paths:
472473
produces:
473474
- application/json
474475
parameters:
476+
- $ref: "#/parameters/app-version"
475477
- in: body
476478
name: body
477479
required: true
@@ -512,6 +514,7 @@ paths:
512514
produces:
513515
- application/json
514516
parameters:
517+
- $ref: "#/parameters/app-version"
515518
- name: challengeId
516519
in: path
517520
required: true
@@ -548,6 +551,7 @@ paths:
548551
produces:
549552
- application/json
550553
parameters:
554+
- $ref: "#/parameters/app-version"
551555
- name: challengeId
552556
in: path
553557
required: true
@@ -593,6 +597,7 @@ paths:
593597
produces:
594598
- application/json
595599
parameters:
600+
- $ref: "#/parameters/app-version"
596601
- name: challengeId
597602
in: path
598603
required: true
@@ -2398,6 +2403,19 @@ parameters:
23982403
minimum: 1
23992404
default: 100
24002405
maximum: 100
2406+
app-version:
2407+
name: app-version
2408+
in: header
2409+
description: >
2410+
The app version:
2411+
2412+
- 1.1.0: With 1.1.0 or later version, challenge-api supports create/update challenge with "skills" data in request payload,
2413+
and with "skills" data in response body when get/search/create/update challenges.
2414+
2415+
- 2.0.0: With 2.0.0 or later version, challenge-api supports "payments" data in response body when get/search/create/update challenges for admin/m2m user.
2416+
required: false
2417+
type: string
2418+
default: 1.0.0
24012419
definitions:
24022420
Challenge:
24032421
type: object
@@ -2643,6 +2661,39 @@ definitions:
26432661
type: string
26442662
description: Auto-generated
26452663
example: Development
2664+
payments:
2665+
type: array
2666+
description: The payments of the challenge, only applicable when "app-version" header >= 2.0.0 for admin/m2m user
2667+
items:
2668+
type: object
2669+
properties:
2670+
handle:
2671+
type: string
2672+
type:
2673+
type: string
2674+
amount:
2675+
type: number
2676+
userId:
2677+
type: number
2678+
skills:
2679+
type: array
2680+
description: The skills of the challenge, only applicable when "app-version" header >= 1.1.0
2681+
items:
2682+
type: object
2683+
properties:
2684+
id:
2685+
type: string
2686+
format: UUID
2687+
name:
2688+
type: string
2689+
category:
2690+
type: object
2691+
properties:
2692+
id:
2693+
type: string
2694+
format: UUID
2695+
name:
2696+
type: string
26462697
required:
26472698
- typeId
26482699
- trackId
@@ -2792,6 +2843,17 @@ definitions:
27922843
required:
27932844
- id
27942845
- roleId
2846+
skills:
2847+
type: array
2848+
description: The ids of the skills to add for the challenge, only applicable when "app-version" header >= 1.1.0
2849+
items:
2850+
type: object
2851+
properties:
2852+
id:
2853+
type: string
2854+
format: UUID
2855+
required:
2856+
- id
27952857
required:
27962858
- typeId
27972859
- trackId
@@ -2975,6 +3037,17 @@ definitions:
29753037
required:
29763038
- id
29773039
- roleId
3040+
skills:
3041+
type: array
3042+
description: The ids of the skills to add for the challenge, only applicable when "app-version" header >= 1.1.0
3043+
items:
3044+
type: object
3045+
properties:
3046+
id:
3047+
type: string
3048+
format: UUID
3049+
required:
3050+
- id
29783051
required:
29793052
- typeId
29803053
- trackId
@@ -3159,6 +3232,17 @@ definitions:
31593232
required:
31603233
- id
31613234
- roleId
3235+
skills:
3236+
type: array
3237+
description: The ids of the skills to add for the challenge, only applicable when "app-version" header >= 1.1.0
3238+
items:
3239+
type: object
3240+
properties:
3241+
id:
3242+
type: string
3243+
format: UUID
3244+
required:
3245+
- id
31623246
SearchChallengeRequestBody:
31633247
type: object
31643248
properties:

src/common/helper.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,16 +1139,41 @@ async function getMembersByHandles(handles) {
11391139
* @returns {Object}
11401140
*/
11411141
async function getStandSkills(ids) {
1142+
1143+
const queryBatches = [];
1144+
const skillIdArg = "&skillId=";
1145+
let queryString = "disablePagination=true";
1146+
1147+
for (const id of ids) {
1148+
const enid = encodeURIComponent(id);
1149+
// When many skill ids, the query string will exceed 2048 limit
1150+
if (queryString.length + skillIdArg.length + enid.length < 2048) {
1151+
queryString += skillIdArg + enid;
1152+
} else {
1153+
queryBatches.push(queryString);
1154+
queryString = "disablePagination=true" + skillIdArg + enid;
1155+
}
1156+
}
1157+
queryBatches.push(queryString);
1158+
1159+
const skillDataPromises = [];
11421160
const token = await m2mHelper.getM2MToken();
1143-
const res = await axios.get(`${config.API_BASE_URL}/v5/standardized-skills/skills`, {
1144-
headers: { Authorization: `Bearer ${token}` },
1145-
params: {
1146-
page: 1,
1147-
perPage: ids.length,
1148-
skillId: ids,
1149-
},
1150-
});
1151-
return res.data;
1161+
for (const batch of queryBatches) {
1162+
skillDataPromises.push(
1163+
(async () => {
1164+
const res = await axios.get(
1165+
`${config.API_BASE_URL}/v5/standardized-skills/skills?${batch}`,
1166+
{
1167+
headers: { Authorization: `Bearer ${token}` },
1168+
}
1169+
);
1170+
return res.data;
1171+
})()
1172+
);
1173+
}
1174+
1175+
const data = await Promise.all(skillDataPromises);
1176+
return _.concat(...data);
11521177
}
11531178

11541179
/**

0 commit comments

Comments
 (0)