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

Commit 7bff5cf

Browse files
authored
Merge pull request #74 from yoution/feature/projectid
feat: add getProjectId api
2 parents 563c520 + f4668a8 commit 7bff5cf

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

docs/swagger.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ paths:
122122
summary: Delete a challenge's migration record, sync record, challenge entry, and resources
123123
tags:
124124
- Migration
125-
operationId: destroyChallenge
125+
operationId: getChallenge
126126
security:
127127
- bearer: []
128128
responses:
@@ -137,6 +137,29 @@ paths:
137137
500:
138138
$ref: '#/definitions/ServerError'
139139

140+
'/challenge-migration/getChallengeProjectId/{roundId}':
141+
get:
142+
parameters:
143+
- name: roundId
144+
in: path
145+
description: The roundId of record
146+
required: true
147+
type: string
148+
summary: get the projectId by roundId
149+
tags:
150+
- Migration
151+
operationId: Challenge
152+
security:
153+
- bearer: []
154+
responses:
155+
200:
156+
schema:
157+
$ref: '#/definitions/ProjectIdObject'
158+
400:
159+
$ref: '#/definitions/BadRequest'
160+
500:
161+
$ref: '#/definitions/ServerError'
162+
140163
'/challenge-migration/sync':
141164
get:
142165
summary: Get Sync status.
@@ -202,6 +225,14 @@ paths:
202225

203226

204227
definitions:
228+
ProjectIdObject:
229+
description: The project id of challenge
230+
type: object
231+
properties:
232+
projectId:
233+
type: number
234+
description: The ProjectId
235+
example: 23234
205236
MigrationStatusObject:
206237
description: The Migration Status Object.
207238
type: object
@@ -284,4 +315,5 @@ definitions:
284315
message:
285316
type: string
286317
description: The conflict error message.
287-
example: Creating a resource with a name already exists.
318+
example: Creating a resource with a name already exists.
319+

src/controllers/apiController.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ async function convertV4TrackToV5 (req, res) {
184184
return res.json(translationService.convertV4TrackToV5(track, subTrack, isTask, tags))
185185
}
186186

187+
async function getChallengeProjectId (req, res) {
188+
const roundId = _.get(req, 'params.roundId')
189+
if (!roundId) {
190+
return res.status(400).json({ message: `Invalid roundId: ${roundId}` })
191+
}
192+
try {
193+
const result = await challengeService.getChallengeProjectId(roundId)
194+
if (result.length > 0) {
195+
return res.json({ projectId: result[0].project_id})
196+
}
197+
return res.status(404).json({ message: 'projectId Not found' })
198+
} catch (e) {
199+
logger.debug(`Error in GetChallengeProjectId: ${e}`)
200+
return res.status(400).json({ message: `Unable to GetChallengeProjectId: ${JSON.stringify(e)}` })
201+
}
202+
}
203+
187204
module.exports = {
188205
queueForMigration,
189206
getMigrationStatus,
@@ -192,5 +209,6 @@ module.exports = {
192209
getSyncStatus,
193210
destroyChallenge,
194211
convertV5TrackToV4,
195-
convertV4TrackToV5
212+
convertV4TrackToV5,
213+
getChallengeProjectId
196214
}

src/routes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,11 @@ module.exports = {
6262
auth: 'jwt',
6363
scopes: [CHALLENGES.WRITE, CHALLENGES.ALL]
6464
}
65+
},
66+
'/challenge-migration/getChallengeProjectId/:roundId': {
67+
get: {
68+
controller: 'apiController',
69+
method: 'getChallengeProjectId'
70+
}
6571
}
6672
}

src/services/challengeInformixService.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ const helper = require('../util/helper')
44
// const getErrorService = require('./errorService')
55
const { executeQueryAsync } = require('../util/informixWrapper')
66

7+
/**
8+
* Get projectId
9+
* @param {Number} roundId the Round ID
10+
*/
11+
async function getProjectIdFromIfx (roundId) {
12+
const sql = `SELECT limit 1
13+
project_id
14+
FROM project_info
15+
WHERE value = ${roundId} and project_info_type_id = 56
16+
`
17+
// logger.info(`projectId SQL: ${sql}`)
18+
return execQuery(sql)
19+
}
20+
721
/**
822
* Get effort hours for a legacyId
923
* @param {Number} legacyId the legacy ID
@@ -680,6 +694,7 @@ async function execQuery (sql) {
680694
module.exports = {
681695
execQuery,
682696
getChallengeInfo,
697+
getProjectIdFromIfx,
683698
getMetadataFromIfx,
684699
getChallengesFromIfx,
685700
getChallengeIdsFromIfx,

src/services/challengeService.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,10 @@ async function getChallengeSubmissionsFromV5API (challengeId, type) {
942942
return { results: [], total: 0 }
943943
}
944944

945+
async function getChallengeProjectId (roundId) {
946+
return challengeInformixService.getProjectIdFromIfx(roundId)
947+
}
948+
945949
module.exports = {
946950
save,
947951
buildV5Challenge,
@@ -962,5 +966,6 @@ module.exports = {
962966
getMMatchFromV4API,
963967
getChallengeTypesFromDynamo,
964968
getChallengeSubmissionsFromV5API,
969+
getChallengeProjectId,
965970
mapTimelineTemplateId
966971
}

0 commit comments

Comments
 (0)