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

Feature/projectid #76

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@ module.exports = {
}
},

COPILOT_PAYMENT_TYPE: process.env.COPILOT_PAYMENT_TYPE || 'copilot'
COPILOT_PAYMENT_TYPE: process.env.COPILOT_PAYMENT_TYPE || 'copilot',
MARATHON_MATCH_PROJECT_INFO_TYPE_ID: 56
}
36 changes: 34 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -284,4 +315,5 @@ definitions:
message:
type: string
description: The conflict error message.
example: Creating a resource with a name already exists.
example: Creating a resource with a name already exists.

20 changes: 19 additions & 1 deletion src/controllers/apiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -192,5 +209,6 @@ module.exports = {
getSyncStatus,
destroyChallenge,
convertV5TrackToV4,
convertV4TrackToV5
convertV4TrackToV5,
getChallengeProjectId
}
6 changes: 6 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ module.exports = {
auth: 'jwt',
scopes: [CHALLENGES.WRITE, CHALLENGES.ALL]
}
},
'/challenge-migration/getChallengeProjectId/:roundId': {
get: {
controller: 'apiController',
method: 'getChallengeProjectId'
}
}
}
16 changes: 16 additions & 0 deletions src/services/challengeInformixService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
const _ = require('lodash')
const config = require('config')
const logger = require('../util/logger')
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 = ${config.MARATHON_MATCH_PROJECT_INFO_TYPE_ID}
`
// logger.info(`projectId SQL: ${sql}`)
return execQuery(sql)
}

/**
* Get effort hours for a legacyId
* @param {Number} legacyId the legacy ID
Expand Down Expand Up @@ -680,6 +695,7 @@ async function execQuery (sql) {
module.exports = {
execQuery,
getChallengeInfo,
getProjectIdFromIfx,
getMetadataFromIfx,
getChallengesFromIfx,
getChallengeIdsFromIfx,
Expand Down
5 changes: 5 additions & 0 deletions src/services/challengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -962,5 +966,6 @@ module.exports = {
getMMatchFromV4API,
getChallengeTypesFromDynamo,
getChallengeSubmissionsFromV5API,
getChallengeProjectId,
mapTimelineTemplateId
}