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

Commit 1189b5a

Browse files
authored
Merge pull request #36 from topcoder-platform/fix-prizeSets
fix the issue with prizeSets
2 parents f1d4801 + 7d47ea2 commit 1189b5a

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/services/syncService.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,12 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
4646
const v5ChallengeObjectFromV4 = await challengeService.buildV5Challenge(legacyId, challengeListing, challengeDetails)
4747
const [v5ChallengeFromAPI] = await challengeService.getChallengeFromV5API(legacyId)
4848

49-
// omit properties that shouldn't be sync'd
50-
// TODO omit other properties?
51-
let challengeObj = _.omit(v5ChallengeObjectFromV4, ['type', 'track', 'typeId', 'trackId'])
52-
53-
if (challengeObj.descriptionFormat !== 'HTML') {
54-
challengeObj = _.omit(challengeObj, ['description', 'privateDescription'])
55-
}
49+
const additionalInformation = {}
5650

5751
// logger.info(`Before V5 Reg Sync: ${challengeObj.numOfRegistrants} ${v5ChallengeFromAPI.numOfRegistrants}`)
5852
try {
5953
const registrants = await resourceService.getResourcesFromV5API(v5ChallengeFromAPI.id, config.SUBMITTER_ROLE_ID)
60-
challengeObj.numOfRegistrants = _.toNumber(registrants.total)
54+
additionalInformation.numOfRegistrants = _.toNumber(registrants.total)
6155
} catch (e) {
6256
logger.error(`Sync :: Failed to load resources for challenge ${v5ChallengeFromAPI.id}`)
6357
logger.logFullError(e)
@@ -66,7 +60,7 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
6660
// logger.info(`Before V5 Sub Sync: ${challengeObj.numOfSubmissions} ${v5ChallengeFromAPI.numOfSubmissions}`)
6761
try {
6862
const submissions = await challengeService.getChallengeSubmissionsFromV5API(legacyId, config.SUBMISSION_TYPE)
69-
challengeObj.numOfSubmissions = _.toNumber(submissions.total) || 0
63+
additionalInformation.numOfSubmissions = _.toNumber(submissions.total) || 0
7064
} catch (e) {
7165
logger.error(`Sync :: Failed to load submissions for challenge ${legacyId}`)
7266
logger.logFullError(e)
@@ -75,15 +69,29 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
7569
if (v5ChallengeObjectFromV4.track.toUpperCase() === V4_TRACKS.DESIGN) {
7670
try {
7771
const submissions = await challengeService.getChallengeSubmissionsFromV5API(legacyId, config.CHECKPOINT_SUBMISSION_TYPE)
78-
challengeObj.numOfCheckpointSubmissions = _.toNumber(submissions.total) || 0
72+
additionalInformation.numOfCheckpointSubmissions = _.toNumber(submissions.total) || 0
7973
} catch (e) {
8074
logger.error(`Sync :: Failed to load checkpoint submissions for challenge ${legacyId}`)
8175
logger.logFullError(e)
8276
}
8377
}
84-
challengeObj.id = v5ChallengeFromAPI.id
8578

86-
return challengeService.save(challengeObj)
79+
const ommittedFields = [['id', 'type', 'track', 'typeId', 'trackId', 'prizeSets']]
80+
81+
if (v5ChallengeObjectFromV4.descriptionFormat !== 'HTML') {
82+
ommittedFields.push('description')
83+
ommittedFields.push('privateDescription')
84+
}
85+
86+
return challengeService.save({
87+
..._.omit(v5ChallengeFromAPI, ['prizeSets']),
88+
..._.omit(v5ChallengeObjectFromV4, ommittedFields),
89+
prizeSets: [
90+
..._.intersectionBy(_.get(v5ChallengeObjectFromV4, 'prizeSets', []).prizeSets, _.get(v5ChallengeFromAPI, 'prizeSets', []).prizeSets, 'type'),
91+
..._.differenceBy(_.get(v5ChallengeFromAPI, 'prizeSets', []).prizeSets, _.get(v5ChallengeObjectFromV4, 'prizeSets', []).prizeSets, 'type')
92+
],
93+
...additionalInformation
94+
})
8795
}
8896

8997
async function processResources (legacyId, challengeId, force) {

0 commit comments

Comments
 (0)