Skip to content

Commit f9833ec

Browse files
Merge pull request #462 from topcoder-platform/develop
Update project info when work item goes into draft state
2 parents 23a8aa3 + e3a1f8b commit f9833ec

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/common/helper.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,31 @@ async function activateProject (projectId, currentUser, name, description) {
583583
}
584584
}
585585

586+
/**
587+
* Update self service project info
588+
* @param {*} projectId the project id
589+
* @param {*} workItemPlannedEndDate the planned end date of the work item
590+
* @param {*} currentUser the current user
591+
*/
592+
async function updateSelfServiceProjectInfo (projectId, workItemPlannedEndDate, currentUser) {
593+
const project = await ensureProjectExist(projectId, currentUser)
594+
const payment = await getProjectPayment(projectId)
595+
const token = await getM2MToken()
596+
const url = `${config.PROJECTS_API_URL}/${projectId}`
597+
const res = await axios.patch(url, {
598+
details: {
599+
...project.details,
600+
paymentProvider: config.DEFAULT_PAYMENT_PROVIDER,
601+
paymentId: payment.id,
602+
paymentIntentId: payment.paymentIntentId,
603+
paymentAmount: payment.amount,
604+
paymentCurrency: payment.currency,
605+
paymentStatus: payment.status,
606+
workItemPlannedEndDate
607+
}
608+
}, { headers: { Authorization: `Bearer ${token}` } })
609+
}
610+
586611
/**
587612
* Get resource roles
588613
* @returns {Promise<Array>} the challenge resources
@@ -1257,5 +1282,6 @@ module.exports = {
12571282
sendSelfServiceNotification,
12581283
getMemberByHandle,
12591284
submitZendeskRequest,
1260-
getMemberById
1285+
getMemberById,
1286+
updateSelfServiceProjectInfo
12611287
}

src/services/ChallengeService.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,18 @@ async function update (currentUser, challengeId, data, isFull) {
16731673
data.endDate = helper.calculateChallengeEndDate(challenge, data)
16741674
}
16751675

1676+
1677+
// PUT HERE
1678+
if (data.status) {
1679+
if (challenge.legacy.selfService && data.status === constants.challengeStatuses.Draft) {
1680+
try {
1681+
await helper.updateSelfServiceProjectInfo(challenge.projectId, data.endDate || challenge.endDate, currentUser)
1682+
} catch (e) {
1683+
logger.debug(`There was an error trying to update the project: ${e.message}`)
1684+
}
1685+
}
1686+
}
1687+
16761688
if (data.winners && data.winners.length && data.winners.length > 0) {
16771689
await validateWinners(data.winners, challengeId)
16781690
}

0 commit comments

Comments
 (0)