Skip to content

issue 57 fix #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
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
28 changes: 28 additions & 0 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const constants = require('../../app-constants')
const models = require('../models')
const HttpStatus = require('http-status-codes')
const moment = require('moment')
const phaseService = require('./PhaseService')

const esClient = helper.getESClient()

Expand Down Expand Up @@ -208,6 +209,9 @@ async function searchChallenges (currentUser, criteria) {
element.type = typeMap.get(element.typeId) || 'Code'
delete element.typeId
})
_.each(result, async element => {
await getPhasesAndPopulate(element)
})

return { total, page: criteria.page, perPage: criteria.perPage, result: await populateSettings(result) }
}
Expand Down Expand Up @@ -481,6 +485,20 @@ async function populateSettings (data) {
return data
}

/**
* Populate phase data from phase API.
* @param {Object} the challenge entity
*/
async function getPhasesAndPopulate (data) {
_.each(data.phases, async p => {
const phase = await phaseService.getPhase(p.id)
p.name = phase.name
if (phase.description) {
p.description = phase.description
}
})
}

/**
* Get challenge.
* @param {Object} currentUser the user who perform operation
Expand Down Expand Up @@ -529,6 +547,8 @@ async function getChallenge (currentUser, id) {
_.unset(challenge, 'privateDescription')
}

getPhasesAndPopulate(challenge)

return populateSettings(challenge)
}

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

delete data.attachmentIds
delete data.termsIds
if (data.phases) {
_.each(data.phases, p => {
delete p.name
if (p.description) {
delete p.description
}
})
}
_.assign(challenge, data)
if (!_.isUndefined(newAttachments)) {
challenge.attachments = newAttachments
Expand Down