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

Commit 0679ebb

Browse files
Merge branch 'develop' into scheduling-api-changes
2 parents 06ea632 + 88c0bd4 commit 0679ebb

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/constants.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const prizeSetTypes = {
99
CheckpointPrizes: 'checkpoint'
1010
}
1111

12+
const challengeStatusOrders = {
13+
draft: 0,
14+
active: 1,
15+
completed: 2,
16+
deleted: 2,
17+
cancelled: 2
18+
}
19+
1220
module.exports = {
13-
prizeSetTypes
21+
prizeSetTypes,
22+
challengeStatusOrders
1423
}

src/services/challengeInformixService.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const { executeQueryAsync } = require('../util/informixWrapper')
99
* @param {Number} legacyId the legacy ID
1010
*/
1111
async function getCopilotPaymentFromIfx (legacyId) {
12-
const sql = `SELECT limit 1 * FROM project_info WHERE project_id = ${_.toInteger(legacyId)} AND project_info_type_id = 49`
13-
const result = await execQuery(sql)
14-
if (result && result[0]) return result[0]
15-
return false
12+
const getCopilotResourceRes = await execQuery(`SELECT limit 1 resource_id as resourceid FROM resource WHERE project_id = ${_.toInteger(legacyId)} AND resource_role_id = 14`)
13+
const copilotResourceId = _.get(getCopilotResourceRes, '[0].resourceid', null)
14+
if (!copilotResourceId) return null
15+
const result = await execQuery(`SELECT amount FROM project_payment where resource_id = ${_.toInteger(copilotResourceId)} AND project_payment_type_id = 4`)
16+
return _.get(result, '[0]', null)
1617
}
1718

1819
/**

src/services/challengeService.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,19 @@ async function buildV5Challenge (legacyId, challengeListing, challengeDetails) {
714714
} else {
715715
newPhase.isOpen = false
716716
}
717+
logger.debug(`Challenge ${legacyId} Phase ${phase.type} id ${newPhase.phaseId} Duration ${v5duration} = ${(v5duration / 60 / 60)} hrs or ${(v5duration / 60 / 60 / 24)} days`)
717718
return newPhase
718719
})
719720
newChallenge.endDate = challengeEndDate
721+
logger.debug(`Final Phase Array ${JSON.stringify(phases)}`)
720722

721723
if (phases.length > 0) {
722724
const registrationPhase = _.find(phases, p => p.name === 'Registration')
723725
const submissionPhase = _.find(phases, p => p.name === 'Submission')
726+
727+
logger.debug(`Registration Phase ${JSON.stringify(registrationPhase)}`)
728+
logger.debug(`Submission Phase ${JSON.stringify(submissionPhase)}`)
729+
724730
newChallenge.currentPhaseNames = _.map(_.filter(phases, p => p.isOpen === true), 'name')
725731
if (registrationPhase) {
726732
newChallenge.registrationStartDate = registrationPhase.actualStartDate || registrationPhase.scheduledStartDate
@@ -741,7 +747,12 @@ async function buildV5Challenge (legacyId, challengeListing, challengeDetails) {
741747

742748
const metadataList = ['allowStockArt', 'drPoints', 'submissionViewable', 'submissionLimit', 'codeRepo', 'environment']
743749
const allMetadata = _.map(metadataList, item => {
744-
if (challengeListing[item]) return { name: item, value: _.toString(challengeListing[item]) }
750+
if (challengeListing[item]) {
751+
if (item === 'submissionLimit') {
752+
return { name: item, value: _.toString(_.get(challengeListing[item], 'count', 0)) }
753+
}
754+
return { name: item, value: _.toString(challengeListing[item]) }
755+
}
745756
})
746757
metadata.push(..._.compact(allMetadata))
747758

src/services/syncService.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const challengeMigrationStatusService = require('../services/challengeMigrationS
88
const migrationService = require('../services/migrationService')
99
const challengeIfxService = require('../services/challengeInformixService')
1010
const { V4_TRACKS } = require('../util/conversionMappings')
11+
const { challengeStatusOrders } = require('../constants')
1112

1213
async function syncLegacyId (legacyId, force) {
1314
// const legacyId = queuedChallenges.items[i].legacyId
@@ -59,6 +60,16 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
5960
// logger.debug(`V5 Object Built from V4: ${JSON.stringify(v5ChallengeObjectFromV4)}`)
6061
// logger.debug(`V5 Object from API: ${JSON.stringify(v5ChallengeFromAPI)}`)
6162

63+
const v4StatusNumber = challengeStatusOrders[_.toLower(v5ChallengeObjectFromV4.status)] || challengeStatusOrders.cancelled
64+
const v5StatusNumber = challengeStatusOrders[_.toLower(v5ChallengeFromAPI.status)] || challengeStatusOrders.cancelled
65+
66+
logger.debug(`v4 Status Number: ${v4StatusNumber} - v5 Status Number: ${v5StatusNumber}`)
67+
68+
if (v4StatusNumber < v5StatusNumber) {
69+
logger.warn(`Status in v4 is: ${_.toLower(v5ChallengeObjectFromV4.status)} - Status in v5 is: ${_.toLower(v5ChallengeFromAPI.status)} NOT updating v5`)
70+
v5ChallengeObjectFromV4.status = v5ChallengeFromAPI.status
71+
}
72+
6273
const additionalInformation = {}
6374

6475
// logger.info(`Before V5 Reg Sync: ${challengeObj.numOfRegistrants} ${v5ChallengeFromAPI.numOfRegistrants}`)
@@ -113,7 +124,7 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
113124
prizes: [
114125
{
115126
type: 'USD',
116-
value: copilotPayment.value
127+
value: copilotPayment.amount
117128
}
118129
],
119130
type: config.COPILOT_PAYMENT_TYPE

0 commit comments

Comments
 (0)