Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 7025ed4

Browse files
committed
fix: generate payments for topcrowd challenges
Signed-off-by: Rakib Ansary <[email protected]>
1 parent 00d652f commit 7025ed4

File tree

4 files changed

+60
-43
lines changed

4 files changed

+60
-43
lines changed

.circleci/config.yml

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
version: 2
22
defaults: &defaults
33
docker:
4-
- image: cimg/python:3.11.0-browsers
4+
- image: cimg/python:3.12.1-browsers
55
install_dependency: &install_dependency
66
name: Installation of build and deployment dependencies.
77
command: |
8-
sudo apt update
9-
sudo apt install jq
10-
sudo apt install python3-pip
11-
sudo pip3 install awscli --upgrade
12-
sudo pip3 install docker-compose
8+
pip3 install awscli --upgrade
139
install_deploysuite: &install_deploysuite
1410
name: Installation of install_deploysuite.
1511
command: |
16-
git clone --branch v1.4.15 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
12+
git clone --branch v1.4.17 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
1713
cp ./../buildscript/master_deploy.sh .
1814
cp ./../buildscript/buildenv.sh .
1915
cp ./../buildscript/awsconfiguration.sh .
@@ -23,38 +19,38 @@ restore_cache_settings_for_build: &restore_cache_settings_for_build
2319
save_cache_settings: &save_cache_settings
2420
key: docker-node-modules-{{ checksum "package-lock.json" }}
2521
paths:
26-
- node_modules
22+
- node_modules
2723

2824
builddeploy_steps: &builddeploy_steps
29-
- checkout
30-
- setup_remote_docker
31-
- run: *install_dependency
32-
- run: *install_deploysuite
33-
- restore_cache: *restore_cache_settings_for_build
34-
- run: ./build.sh ${APPNAME}
35-
- save_cache: *save_cache_settings
36-
- deploy:
37-
name: Running MasterScript.
38-
command: |
39-
./awsconfiguration.sh $DEPLOY_ENV
40-
source awsenvconf
41-
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
42-
source buildenvvar
43-
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-global-informix-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
25+
- checkout
26+
- setup_remote_docker
27+
- run: *install_dependency
28+
- run: *install_deploysuite
29+
- restore_cache: *restore_cache_settings_for_build
30+
- run: ./build.sh ${APPNAME}
31+
- save_cache: *save_cache_settings
32+
- deploy:
33+
name: Running MasterScript.
34+
command: |
35+
./awsconfiguration.sh $DEPLOY_ENV
36+
source awsenvconf
37+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
38+
source buildenvvar
39+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-global-informix-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
4440
4541
4642
jobs:
4743
# Build & Deploy against development backend
4844
"build-dev":
49-
<<: *defaults
45+
!!merge <<: *defaults
5046
environment:
5147
DEPLOY_ENV: "DEV"
5248
LOGICAL_ENV: "dev"
5349
APPNAME: "legacy-payment-processor"
5450
steps: *builddeploy_steps
5551

5652
"build-prod":
57-
<<: *defaults
53+
!!merge <<: *defaults
5854
environment:
5955
DEPLOY_ENV: "PROD"
6056
LOGICAL_ENV: "prod"
@@ -65,18 +61,19 @@ workflows:
6561
version: 2
6662
build:
6763
jobs:
68-
# Development builds are executed on "develop" branch only.
69-
- "build-dev":
70-
context : org-global
71-
filters:
72-
branches:
73-
only:
74-
- develop
64+
# Development builds are executed on "develop" branch only.
65+
- "build-dev":
66+
context: org-global
67+
filters:
68+
branches:
69+
only:
70+
- develop
71+
- TOPCROWD-PAYMENTS-FIX
7572

76-
# Production builds are exectuted only on tagged commits to the
77-
# master branch.
78-
- "build-prod":
79-
context : org-global
80-
filters:
81-
branches:
82-
only: master
73+
# Production builds are exectuted only on tagged commits to the
74+
# master branch.
75+
- "build-prod":
76+
context: org-global
77+
filters:
78+
branches:
79+
only: master

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ module.exports = {
5151
PAYMENT_METHOD_ID: process.env.PAYMENT_METHOD_ID || 1,
5252
CHARITY_IND: process.env.CHARITY_IND || 0,
5353
INSTALLMENT_NUMBER: process.env.INSTALLMENT_NUMBER || 1,
54-
COPILOT_ROLE_ID: process.env.COPILOT_ROLE_ID || 'cfe12b3f-2a24-4639-9d8b-ec86726f76bd'
54+
COPILOT_ROLE_ID: process.env.COPILOT_ROLE_ID || 'cfe12b3f-2a24-4639-9d8b-ec86726f76bd',
55+
TOPCROWD_CHALLENGE_TEMPLATE_ID: "517e76b0-8824-4e72-9b48-a1ebde1793a8"
5556
}

src/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, a
4444
return
4545
}
4646

47+
const timelineTemplateId = _.get(messageJSON.payload, 'timelineTemplateId');
48+
4749
// Currently only process payments for challenges with `legacy.pureV5Task: true` or `legacy.pureV5: true`
48-
if (!_.get(messageJSON.payload, 'legacy.pureV5Task', false) && !_.get(messageJSON.payload, 'legacy.pureV5', false)) {
49-
logger.info(`Challenge Legacy Object ${JSON.stringify(_.get(messageJSON.payload, 'legacy'))} does not have legacy.pureV5Task: true or legacy.pureV5: true`)
50+
if (!_.get(messageJSON.payload, 'legacy.pureV5Task', false) && !_.get(messageJSON.payload, 'legacy.pureV5', false) && timelineTemplateId != config.get('TOPCROWD_CHALLENGE_TEMPLATE_ID')) {
51+
logger.info(`Challenge Legacy Object ${JSON.stringify(_.get(messageJSON.payload, 'legacy'))} does not have legacy.pureV5Task: true or legacy.pureV5: true or timelineTemplateId: ${timelineTemplateId}.`)
5052
await consumer.commitOffset({ topic, partition, offset: m.offset })
5153
return
5254
}

src/services/processorService.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async function processUpdate(message) {
1818
const createUserId = await helper.getUserId(message.payload.createdBy)
1919
const legacyId = _.get(message, 'payload.legacyId', null)
2020
const v5ChallengeId = _.get(message, 'payload.id', null)
21+
const timelineTemplateId = _.get(message.payload, 'timelineTemplateId')
2122

2223
if (!v5ChallengeId || v5ChallengeId === '') {
2324
logger.error('Payload of challenge does not contain a v5 Challenge UUID')
@@ -47,7 +48,23 @@ async function processUpdate(message) {
4748
const checkpointWinnerMembers = _.sortBy(_.filter(_.get(message.payload, 'winners', []), w => w.type === 'checkpoint'), ['placement'])
4849
if (_.isEmpty(winnerPrizes)) {
4950
logger.warn(`For challenge ${v5ChallengeId}, no winner payment avaiable`)
50-
} else if (winnerPrizes.length !== winnerMembers.length) {
51+
} else if (timelineTemplateId == config.get('TOPCROWD_CHALLENGE_TEMPLATE_ID')) {
52+
try {
53+
for (let i = 0; i < winnerMembers.length; i++) {
54+
const payment = _.assign({
55+
memberId: winnerMembers[i].userId,
56+
amount: winnerPrizes[i].value,
57+
desc: `Payment - ${message.payload.name} - ${winnerMembers[i].placement} Place`,
58+
typeId: config.WINNER_PAYMENT_TYPE_ID
59+
}, basePayment)
60+
61+
logger.info(`TopCrowd Challenge winner ${payment.memberId} payment object details: ` + JSON.stringify(payment))
62+
await paymentService.createPayment(payment)
63+
}
64+
} catch (error) {
65+
logger.error(`For challenge ${v5ChallengeId}, add winner payments error: ${error}`)
66+
}
67+
}else if (winnerPrizes.length !== winnerMembers.length) {
5168
logger.error(`For challenge ${v5ChallengeId}, there is ${winnerPrizes.length} user prizes but ${winnerMembers.length} winners`)
5269
} else {
5370
try {

0 commit comments

Comments
 (0)