Skip to content

Commit 15718ec

Browse files
authored
Merge pull request #623 from topcoder-platform/dev
Prod release
2 parents c696428 + cd525b2 commit 15718ec

File tree

7 files changed

+34
-43
lines changed

7 files changed

+34
-43
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ workflows:
8383
branches:
8484
only:
8585
- dev
86-
- fix/schema
86+
- fix/floating-point-arhithmetic
8787

8888
- "build-qa":
8989
context: org-global
9090
filters:
9191
branches:
9292
only:
93-
- refactor/domain-challenge
93+
- qa
9494

9595
# Production builds are exectuted only on tagged commits to the
9696
# master branch.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/challenge-api/tree/d
2222

2323
- [Resources API](https://github.com/topcoder-platform/resources-api)
2424
- [ES Processor](https://github.com/topcoder-platform/challenge-processor-es) - Updates data in ElasticSearch
25-
- [Legacy Processor](https://github.com/topcoder-platform/legacy-challenge-processor) - Moves data from DynamoDB back to Informix
26-
- [Legacy Migration Script](https://github.com/topcoder-platform/legacy-challenge-migration-script) - Moves data from Informix to DynamoDB
27-
- [Frontend App](https://github.com/topcoder-platform/challenge-engine-ui)
25+
- [Domain Challenge](https://github.com/topcoder-platform/domain-challenge) - Domain Challenge
2826

2927
## Prerequisites
3028

31-
- [NodeJS](https://nodejs.org/en/) (v10)
29+
- [NodeJS](https://nodejs.org/en/) (v18+)
3230
- [AWS S3](https://aws.amazon.com/s3/)
3331
- [Elasticsearch v6](https://www.elastic.co/)
3432
- [Docker](https://www.docker.com/)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"body-parser": "^1.15.1",
5252
"config": "^3.0.1",
5353
"cors": "^2.7.1",
54+
"decimal.js": "^10.4.3",
5455
"deep-equal": "^2.2.0",
5556
"dotenv": "^8.2.0",
5657
"elasticsearch": "^16.7.3",

src/common/challenge-helper.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const config = require("config");
88
const helper = require("./helper");
99
const constants = require("../../app-constants");
1010
const axios = require("axios");
11+
const Decimal = require("decimal.js");
1112
const { getM2MToken } = require("./m2m-helper");
1213
const { hasAdminRole } = require("./role-helper");
1314
const { ensureAcessibilityToModifiedGroups } = require("./group-helper");
@@ -350,7 +351,7 @@ class ChallengeHelper {
350351
convertPrizeSetValuesToCents(prizeSets) {
351352
prizeSets.forEach((prizeSet) => {
352353
prizeSet.prizes.forEach((prize) => {
353-
prize.amountInCents = prize.value * 100;
354+
prize.amountInCents = new Decimal(prize.value).mul(100).toNumber();
354355
delete prize.value;
355356
});
356357
});
@@ -360,13 +361,17 @@ class ChallengeHelper {
360361
prizeSets.forEach((prizeSet) => {
361362
prizeSet.prizes.forEach((prize) => {
362363
if (prize.amountInCents != null) {
363-
prize.value = prize.amountInCents / 100;
364+
prize.value = parseFloat(new Decimal(prize.amountInCents).div(100).toFixed(2));
365+
364366
delete prize.amountInCents;
365367
}
366368
});
367369
});
368370
if (overview && !_.isUndefined(overview.totalPrizesInCents)) {
369-
overview.totalPrizes = overview.totalPrizesInCents / 100;
371+
overview.totalPrizes = parseFloat(
372+
new Decimal(overview.totalPrizesInCents).div(100).toFixed(2)
373+
);
374+
370375
delete overview.totalPrizesInCents;
371376
}
372377
}

src/common/helper.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -754,36 +754,21 @@ function calculateChallengeEndDate(challenge, data) {
754754
async function listChallengesByMember(memberId) {
755755
const token = await m2mHelper.getM2MToken();
756756
let allIds = [];
757-
// get search is paginated, we need to get all pages' data
758-
let page = 1;
759-
while (true) {
760-
let result = {};
761-
try {
762-
result = await axios.get(`${config.RESOURCES_API_URL}/${memberId}/challenges`, {
763-
headers: { Authorization: `Bearer ${token}` },
764-
params: {
765-
page,
766-
perPage: 10000,
767-
},
768-
});
769-
} catch (e) {
770-
// only log the error but don't throw it, so the following logic can still be executed.
771-
logger.debug(`Failed to get challenges that accessible to the memberId ${memberId}`, e);
772-
}
773-
const ids = result.data || [];
774-
if (ids.length === 0) {
775-
break;
776-
}
777-
allIds = allIds.concat(ids);
778-
page += 1;
779-
if (
780-
result.headers &&
781-
result.headers["x-total-pages"] &&
782-
page > Number(result.headers["x-total-pages"])
783-
) {
784-
break;
785-
}
757+
758+
try {
759+
const result = await axios.get(`${config.RESOURCES_API_URL}/${memberId}/challenges`, {
760+
headers: { Authorization: `Bearer ${token}` },
761+
params: {
762+
useScroll: true,
763+
},
764+
});
765+
766+
allIds = result.data || [];
767+
} catch (e) {
768+
// only log the error but don't throw it, so the following logic can still be executed.
769+
logger.debug(`Failed to get challenges that accessible to the memberId ${memberId}`, e);
786770
}
771+
787772
return allIds;
788773
}
789774

src/services/ChallengeService.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ async function searchChallenges(currentUser, criteria) {
149149
_.includes(config.SELF_SERVICE_WHITELIST_HANDLES, currentUser.handle.toLowerCase()));
150150

151151
const includedTrackIds = _.isArray(criteria.trackIds) ? criteria.trackIds : [];
152-
153152
const includedTypeIds = _.isArray(criteria.typeIds) ? criteria.typeIds : [];
154153

155154
if (criteria.type) {
@@ -168,7 +167,6 @@ async function searchChallenges(currentUser, criteria) {
168167
criteria.trackId = _.get(trackSearchRes, "result[0].id");
169168
}
170169
}
171-
172170
if (criteria.types) {
173171
for (const t of criteria.types) {
174172
const typeSearchRes = await ChallengeTypeService.searchChallengeTypes({ abbreviation: t });
@@ -187,7 +185,6 @@ async function searchChallenges(currentUser, criteria) {
187185
}
188186
}
189187
}
190-
191188
if (criteria.typeId) {
192189
includedTypeIds.push(criteria.typeId);
193190
}
@@ -604,10 +601,10 @@ async function searchChallenges(currentUser, criteria) {
604601
match_phrase: { "task.isAssigned": criteria.taskIsAssigned },
605602
});
606603
}
607-
if (criteria.taskMemberId || criteria.memberId) {
604+
if (criteria.taskMemberId) {
608605
boolQuery.push({
609606
match_phrase: {
610-
"task.memberId": criteria.taskMemberId || criteria.memberId,
607+
"task.memberId": criteria.taskMemberId,
611608
},
612609
});
613610
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,11 @@ decamelize@^1.2.0:
10581058
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
10591059
integrity sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==
10601060

1061+
decimal.js@^10.4.3:
1062+
version "10.4.3"
1063+
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23"
1064+
integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==
1065+
10611066
deep-eql@^4.1.2:
10621067
version "4.1.3"
10631068
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d"

0 commit comments

Comments
 (0)