Skip to content

Commit 8bc28f7

Browse files
Fix V5 Project BA issues
1 parent 9a048d3 commit 8bc28f7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/common/helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ async function getProjectDefaultTerms (projectId) {
757757
* @param {Number} projectId The id of the project for which to get the default terms of use
758758
* @returns {Promise<Number>} The billing account ID
759759
*/
760-
async function getProjectBillingInformation (projectId) {
760+
async function getProjectBillingInformation (projectId) {
761761
const token = await getM2MToken()
762762
const projectUrl = `${config.PROJECTS_API_URL}/${projectId}/billingAccount`
763763
try {
@@ -773,7 +773,7 @@ async function getProjectBillingInformation (projectId) {
773773
}
774774
} catch (err) {
775775
if (_.get(err, 'response.status') === HttpStatus.NOT_FOUND) {
776-
throw new errors.BadRequestError(`Project with id: ${projectId} doesn't exist`)
776+
return null
777777
} else {
778778
// re-throw other error
779779
throw err

src/services/ChallengeService.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,10 @@ async function createChallenge (currentUser, challenge) {
861861
}
862862
const { track, type } = await validateChallengeData(challenge)
863863
const { billingAccountId, markup } = await helper.getProjectBillingInformation(_.get(challenge, 'projectId'))
864-
if (_.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
864+
if (billingAccountId && _.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
865865
_.set(challenge, 'billing.billingAccountId', billingAccountId)
866866
}
867-
if (_.isUndefined(_.get(challenge, 'billing.markup'))) {
867+
if (markup && _.isUndefined(_.get(challenge, 'billing.markup'))) {
868868
_.set(challenge, 'billing.markup', markup)
869869
}
870870
if (_.get(type, 'isTask')) {
@@ -1241,10 +1241,10 @@ async function update (currentUser, challengeId, data, isFull) {
12411241

12421242
const challenge = await helper.getById('Challenge', challengeId)
12431243
const { billingAccountId, markup } = await helper.getProjectBillingInformation(_.get(challenge, 'projectId'))
1244-
if (_.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
1244+
if (billingAccountId && _.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
12451245
_.set(data, 'billing.billingAccountId', billingAccountId)
12461246
}
1247-
if (_.isUndefined(_.get(challenge, 'billing.markup'))) {
1247+
if (markup && _.isUndefined(_.get(challenge, 'billing.markup'))) {
12481248
_.set(data, 'billing.markup', markup)
12491249
}
12501250
if (data.status) {
@@ -1253,7 +1253,7 @@ async function update (currentUser, challengeId, data, isFull) {
12531253
throw new errors.BadRequestError('You cannot activate the challenge as it has not been created on legacy yet. Please try again later or contact support.')
12541254
}
12551255
// if activating a challenge, the challenge must have a billing account id
1256-
if ((!_.get(challenge, 'billing.billingAccountId') || _.get(challenge, 'billing.billingAccountId') === null) &&
1256+
if ((!billingAccountId || billingAccountId === null) &&
12571257
challenge.status === constants.challengeStatuses.Draft) {
12581258
throw new errors.BadRequestError('Cannot Activate this project, it has no active billing account.')
12591259
}

0 commit comments

Comments
 (0)