Skip to content

Commit 93b651c

Browse files
Merge pull request #69 from rashmi73/issue_57
issue 57 fix
2 parents ac813b3 + d517add commit 93b651c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/services/ChallengeService.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const constants = require('../../app-constants')
1313
const models = require('../models')
1414
const HttpStatus = require('http-status-codes')
1515
const moment = require('moment')
16+
const phaseService = require('./PhaseService')
1617

1718
const esClient = helper.getESClient()
1819

@@ -239,6 +240,9 @@ async function searchChallenges (currentUser, criteria) {
239240
element.type = typeMap.get(element.typeId) || 'Code'
240241
delete element.typeId
241242
})
243+
_.each(result, async element => {
244+
await getPhasesAndPopulate(element)
245+
})
242246

243247
return { total, page: criteria.page, perPage: criteria.perPage, result: await populateSettings(result) }
244248
}
@@ -512,6 +516,20 @@ async function populateSettings (data) {
512516
return data
513517
}
514518

519+
/**
520+
* Populate phase data from phase API.
521+
* @param {Object} the challenge entity
522+
*/
523+
async function getPhasesAndPopulate (data) {
524+
_.each(data.phases, async p => {
525+
const phase = await phaseService.getPhase(p.id)
526+
p.name = phase.name
527+
if (phase.description) {
528+
p.description = phase.description
529+
}
530+
})
531+
}
532+
515533
/**
516534
* Get challenge.
517535
* @param {Object} currentUser the user who perform operation
@@ -560,6 +578,8 @@ async function getChallenge (currentUser, id) {
560578
_.unset(challenge, 'privateDescription')
561579
}
562580

581+
getPhasesAndPopulate(challenge)
582+
563583
return populateSettings(challenge)
564584
}
565585

@@ -988,6 +1008,14 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
9881008

9891009
delete data.attachmentIds
9901010
delete data.termsIds
1011+
if (data.phases) {
1012+
_.each(data.phases, p => {
1013+
delete p.name
1014+
if (p.description) {
1015+
delete p.description
1016+
}
1017+
})
1018+
}
9911019
_.assign(challenge, data)
9921020
if (!_.isUndefined(newAttachments)) {
9931021
challenge.attachments = newAttachments

0 commit comments

Comments
 (0)