Skip to content

Update project info when work item goes into draft state #462

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 3 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
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: 27 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,31 @@ async function activateProject (projectId, currentUser, name, description) {
}
}

/**
* Update self service project info
* @param {*} projectId the project id
* @param {*} workItemPlannedEndDate the planned end date of the work item
* @param {*} currentUser the current user
*/
async function updateSelfServiceProjectInfo (projectId, workItemPlannedEndDate, currentUser) {
const project = await ensureProjectExist(projectId, currentUser)
const payment = await getProjectPayment(projectId)
const token = await getM2MToken()
const url = `${config.PROJECTS_API_URL}/${projectId}`
const res = await axios.patch(url, {
details: {
...project.details,
paymentProvider: config.DEFAULT_PAYMENT_PROVIDER,
paymentId: payment.id,
paymentIntentId: payment.paymentIntentId,
paymentAmount: payment.amount,
paymentCurrency: payment.currency,
paymentStatus: payment.status,
workItemPlannedEndDate
}
}, { headers: { Authorization: `Bearer ${token}` } })
}

/**
* Get resource roles
* @returns {Promise<Array>} the challenge resources
Expand Down Expand Up @@ -1257,5 +1282,6 @@ module.exports = {
sendSelfServiceNotification,
getMemberByHandle,
submitZendeskRequest,
getMemberById
getMemberById,
updateSelfServiceProjectInfo
}
12 changes: 12 additions & 0 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,18 @@ async function update (currentUser, challengeId, data, isFull) {
data.endDate = helper.calculateChallengeEndDate(challenge, data)
}


// PUT HERE
if (data.status) {
if (challenge.legacy.selfService && data.status === constants.challengeStatuses.Draft) {
try {
await helper.updateSelfServiceProjectInfo(challenge.projectId, data.endDate || challenge.endDate, currentUser)
} catch (e) {
logger.debug(`There was an error trying to update the project: ${e.message}`)
}
}
}

if (data.winners && data.winners.length && data.winners.length > 0) {
await validateWinners(data.winners, challengeId)
}
Expand Down