Skip to content

fix: populate 'winners' array during payments #237

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 2 commits into from
May 11, 2021
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
17 changes: 17 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,22 @@ async function getMemberDetailsByHandles (handles) {
return _.get(res.body, 'result.content')
}

/**
* Get topcoder member details by handle.
*
* @param {String} handle the user handle
* @returns {Object} the member details
*/
async function getV3MemberDetailsByHandle (handle) {
const token = await getM2MToken()
const res = await request
.get(`${config.TOPCODER_MEMBERS_API}/${handle}`)
.set('Authorization', `Bearer ${token}`)
.set('Accept', 'application/json')
localLogger.debug({ context: 'getV3MemberDetailsByHandle', message: `response body: ${JSON.stringify(res.body)}` })
return _.get(res.body, 'result.content')
}

/**
* Find topcoder members by email.
*
Expand Down Expand Up @@ -1423,6 +1439,7 @@ module.exports = {
getAuditM2Muser,
checkIsMemberOfProject,
getMemberDetailsByHandles,
getV3MemberDetailsByHandle,
getMemberDetailsByEmails,
createProjectMember,
listProjectMembers,
Expand Down
13 changes: 10 additions & 3 deletions src/services/PaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function createPayment (options) {
const challengeId = await createChallenge(options, token)
await addResourceToChallenge(challengeId, options.userHandle, token)
await activateChallenge(challengeId, token)
const completedChallenge = await closeChallenge(challengeId, token)
const completedChallenge = await closeChallenge(challengeId, options.userHandle, token)
return completedChallenge
}

Expand Down Expand Up @@ -146,14 +146,21 @@ async function activateChallenge (id, token) {
/**
* closes the topcoder challenge
* @param {String} id the challenge id
* @param {String} userHandle the user handle
* @param {String} token m2m token
* @returns {Object} the closed challenge
*/
async function closeChallenge (id, token) {
async function closeChallenge (id, userHandle, token) {
localLogger.info({ context: 'closeChallenge', message: `Closing challenge ${id}` })
try {
const { userId } = await helper.getV3MemberDetailsByHandle(userHandle)
const body = {
status: constants.ChallengeStatus.COMPLETED
status: constants.ChallengeStatus.COMPLETED,
winners: [{
userId,
handle: userHandle,
placement: 1
}]
}
const response = await helper.updateChallenge(id, body, token)
localLogger.info({ context: 'closeChallenge', message: `Challenge ${id} is closed successfully.` })
Expand Down