Skip to content

Commit d517add

Browse files
authored
Update ChallengeService.js
1 parent aa7bffd commit d517add

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

@@ -208,6 +209,9 @@ async function searchChallenges (currentUser, criteria) {
208209
element.type = typeMap.get(element.typeId) || 'Code'
209210
delete element.typeId
210211
})
212+
_.each(result, async element => {
213+
await getPhasesAndPopulate(element)
214+
})
211215

212216
return { total, page: criteria.page, perPage: criteria.perPage, result: await populateSettings(result) }
213217
}
@@ -481,6 +485,20 @@ async function populateSettings (data) {
481485
return data
482486
}
483487

488+
/**
489+
* Populate phase data from phase API.
490+
* @param {Object} the challenge entity
491+
*/
492+
async function getPhasesAndPopulate (data) {
493+
_.each(data.phases, async p => {
494+
const phase = await phaseService.getPhase(p.id)
495+
p.name = phase.name
496+
if (phase.description) {
497+
p.description = phase.description
498+
}
499+
})
500+
}
501+
484502
/**
485503
* Get challenge.
486504
* @param {Object} currentUser the user who perform operation
@@ -529,6 +547,8 @@ async function getChallenge (currentUser, id) {
529547
_.unset(challenge, 'privateDescription')
530548
}
531549

550+
getPhasesAndPopulate(challenge)
551+
532552
return populateSettings(challenge)
533553
}
534554

@@ -952,6 +972,14 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
952972

953973
delete data.attachmentIds
954974
delete data.termsIds
975+
if (data.phases) {
976+
_.each(data.phases, p => {
977+
delete p.name
978+
if (p.description) {
979+
delete p.description
980+
}
981+
})
982+
}
955983
_.assign(challenge, data)
956984
if (!_.isUndefined(newAttachments)) {
957985
challenge.attachments = newAttachments

0 commit comments

Comments
 (0)