From f4668a81bb114979782cf8b95a84a53a721eab74 Mon Sep 17 00:00:00 2001 From: yoution Date: Fri, 27 May 2022 22:44:08 +0800 Subject: [PATCH] feat: add getProjectId api --- docs/swagger.yaml | 36 ++++++++++++++++++++++-- src/controllers/apiController.js | 20 ++++++++++++- src/routes.js | 6 ++++ src/services/challengeInformixService.js | 15 ++++++++++ src/services/challengeService.js | 5 ++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 693020c..f77234a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -122,7 +122,7 @@ paths: summary: Delete a challenge's migration record, sync record, challenge entry, and resources tags: - Migration - operationId: destroyChallenge + operationId: getChallenge security: - bearer: [] responses: @@ -137,6 +137,29 @@ paths: 500: $ref: '#/definitions/ServerError' + '/challenge-migration/getChallengeProjectId/{roundId}': + get: + parameters: + - name: roundId + in: path + description: The roundId of record + required: true + type: string + summary: get the projectId by roundId + tags: + - Migration + operationId: Challenge + security: + - bearer: [] + responses: + 200: + schema: + $ref: '#/definitions/ProjectIdObject' + 400: + $ref: '#/definitions/BadRequest' + 500: + $ref: '#/definitions/ServerError' + '/challenge-migration/sync': get: summary: Get Sync status. @@ -202,6 +225,14 @@ paths: definitions: + ProjectIdObject: + description: The project id of challenge + type: object + properties: + projectId: + type: number + description: The ProjectId + example: 23234 MigrationStatusObject: description: The Migration Status Object. type: object @@ -284,4 +315,5 @@ definitions: message: type: string description: The conflict error message. - example: Creating a resource with a name already exists. \ No newline at end of file + example: Creating a resource with a name already exists. + diff --git a/src/controllers/apiController.js b/src/controllers/apiController.js index a0d59ed..c8a1831 100644 --- a/src/controllers/apiController.js +++ b/src/controllers/apiController.js @@ -184,6 +184,23 @@ async function convertV4TrackToV5 (req, res) { return res.json(translationService.convertV4TrackToV5(track, subTrack, isTask, tags)) } +async function getChallengeProjectId (req, res) { + const roundId = _.get(req, 'params.roundId') + if (!roundId) { + return res.status(400).json({ message: `Invalid roundId: ${roundId}` }) + } + try { + const result = await challengeService.getChallengeProjectId(roundId) + if (result.length > 0) { + return res.json({ projectId: result[0].project_id}) + } + return res.status(404).json({ message: 'projectId Not found' }) + } catch (e) { + logger.debug(`Error in GetChallengeProjectId: ${e}`) + return res.status(400).json({ message: `Unable to GetChallengeProjectId: ${JSON.stringify(e)}` }) + } +} + module.exports = { queueForMigration, getMigrationStatus, @@ -192,5 +209,6 @@ module.exports = { getSyncStatus, destroyChallenge, convertV5TrackToV4, - convertV4TrackToV5 + convertV4TrackToV5, + getChallengeProjectId } diff --git a/src/routes.js b/src/routes.js index 1a1c7cb..3be30de 100644 --- a/src/routes.js +++ b/src/routes.js @@ -62,5 +62,11 @@ module.exports = { auth: 'jwt', scopes: [CHALLENGES.WRITE, CHALLENGES.ALL] } + }, + '/challenge-migration/getChallengeProjectId/:roundId': { + get: { + controller: 'apiController', + method: 'getChallengeProjectId' + } } } diff --git a/src/services/challengeInformixService.js b/src/services/challengeInformixService.js index 2343bab..4279e1f 100644 --- a/src/services/challengeInformixService.js +++ b/src/services/challengeInformixService.js @@ -4,6 +4,20 @@ const helper = require('../util/helper') // const getErrorService = require('./errorService') const { executeQueryAsync } = require('../util/informixWrapper') +/** + * Get projectId + * @param {Number} roundId the Round ID + */ +async function getProjectIdFromIfx (roundId) { + const sql = `SELECT limit 1 + project_id + FROM project_info + WHERE value = ${roundId} and project_info_type_id = 56 + ` + // logger.info(`projectId SQL: ${sql}`) + return execQuery(sql) +} + /** * Get effort hours for a legacyId * @param {Number} legacyId the legacy ID @@ -680,6 +694,7 @@ async function execQuery (sql) { module.exports = { execQuery, getChallengeInfo, + getProjectIdFromIfx, getMetadataFromIfx, getChallengesFromIfx, getChallengeIdsFromIfx, diff --git a/src/services/challengeService.js b/src/services/challengeService.js index 8576a20..af30ad4 100644 --- a/src/services/challengeService.js +++ b/src/services/challengeService.js @@ -942,6 +942,10 @@ async function getChallengeSubmissionsFromV5API (challengeId, type) { return { results: [], total: 0 } } +async function getChallengeProjectId (roundId) { + return challengeInformixService.getProjectIdFromIfx(roundId) +} + module.exports = { save, buildV5Challenge, @@ -962,5 +966,6 @@ module.exports = { getMMatchFromV4API, getChallengeTypesFromDynamo, getChallengeSubmissionsFromV5API, + getChallengeProjectId, mapTimelineTemplateId }