Skip to content

Commit 4c0b820

Browse files
author
Aranyajit
committed
update challenge for non mandatory project id
1 parent dddc534 commit 4c0b820

File tree

4 files changed

+1230
-263
lines changed

4 files changed

+1230
-263
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"dev": "nodemon app.js",
99
"lint": "prettier src/**/*.js",
1010
"lint:fix": "prettier --write src/**/*.js",
11+
"standard-lint": "standard",
12+
"standard-lint:fix": "standard --fix",
1113
"init-es": "node src/init-es.js",
1214
"init-db": "node src/init-db.js",
1315
"sync-es": "node src/scripts/sync-es.js",
@@ -37,13 +39,14 @@
3739
"mocha-prepare": "^0.1.0",
3840
"nodemon": "^2.0.20",
3941
"nyc": "^14.0.0",
40-
"prettier": "^2.8.1"
42+
"prettier": "^2.8.1",
43+
"standard": "^17.1.0"
4144
},
4245
"dependencies": {
4346
"@grpc/grpc-js": "^1.8.12",
4447
"@opensearch-project/opensearch": "^2.2.0",
45-
"@topcoder-framework/domain-challenge": "^0.24.1",
4648
"@topcoder-framework/domain-acl": "^0.24.0",
49+
"@topcoder-framework/domain-challenge": "^0.24.1",
4750
"@topcoder-framework/lib-common": "^0.24.1",
4851
"aws-sdk": "^2.1145.0",
4952
"axios": "^0.19.0",

src/common/challenge-helper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ChallengeHelper {
172172
if (
173173
challenge.legacy.selfService == null &&
174174
challenge.projectId == null &&
175-
!_.includes(config.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID, challenge.timelineTemplateId)
175+
this.isProjectIdRequired(challenge.timelineTemplateId)
176176
) {
177177
throw new errors.BadRequestError("projectId is required for non self-service challenges.");
178178
}
@@ -528,6 +528,11 @@ class ChallengeHelper {
528528
delete overview.totalPrizesInCents;
529529
}
530530
}
531+
532+
isProjectIdRequired(timelineTemplateId) {
533+
if (!_.includes(config.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID, timelineTemplateId)) return true;
534+
return false;
535+
}
531536
}
532537

533538
module.exports = new ChallengeHelper();

src/services/ChallengeService.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,7 @@ async function createChallenge(currentUser, challenge, userToken) {
941941
console.log("TYPE", prizeTypeTmp);
942942
if (challenge.legacy.selfService) {
943943
// if self-service, create a new project (what about if projectId is provided in the payload? confirm with business!)
944-
if (
945-
!challenge.projectId &&
946-
!_.includes(config.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID, challenge.timelineTemplateId)
947-
) {
944+
if (!challenge.projectId && challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
948945
const selfServiceProjectName = `Self service - ${currentUser.handle} - ${challenge.name}`;
949946
challenge.projectId = await helper.createSelfServiceProject(
950947
selfServiceProjectName,
@@ -966,7 +963,7 @@ async function createChallenge(currentUser, challenge, userToken) {
966963
}
967964

968965
/** Ensure project exists, and set direct project id, billing account id & markup */
969-
if (!_.includes(config.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID, challenge.timelineTemplateId)) {
966+
if (challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
970967
const { projectId } = challenge;
971968

972969
const { directProjectId } = await projectHelper.getProject(projectId, currentUser);
@@ -1523,13 +1520,18 @@ async function updateChallenge(currentUser, challengeId, data) {
15231520
convertPrizeSetValuesToDollars(challenge.prizeSets, challenge.overview);
15241521
}
15251522

1526-
const projectId = _.get(challenge, "projectId");
1523+
let projectId;
1524+
if (challengeHelper.isProjectIdRequired(challenge.timelineTemplateId ?? "")) {
1525+
projectId = _.get(challenge, "projectId");
15271526

1528-
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId);
1527+
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(
1528+
projectId
1529+
);
15291530

1530-
if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
1531-
_.set(data, "billing.billingAccountId", billingAccountId);
1532-
_.set(data, "billing.markup", markup || 0);
1531+
if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
1532+
_.set(data, "billing.billingAccountId", billingAccountId);
1533+
_.set(data, "billing.markup", markup || 0);
1534+
}
15331535
}
15341536

15351537
// Make sure the user cannot change the direct project ID
@@ -1578,7 +1580,8 @@ async function updateChallenge(currentUser, challengeId, data) {
15781580
if (
15791581
(data.status === constants.challengeStatuses.Approved ||
15801582
data.status === constants.challengeStatuses.Active) &&
1581-
challenge.status !== constants.challengeStatuses.Active
1583+
challenge.status !== constants.challengeStatuses.Active &&
1584+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
15821585
) {
15831586
try {
15841587
const selfServiceProjectName = `Self service - ${challenge.createdBy} - ${challenge.name}`;
@@ -1614,7 +1617,10 @@ async function updateChallenge(currentUser, challengeId, data) {
16141617
}
16151618
}
16161619

1617-
if (data.status === constants.challengeStatuses.Draft) {
1620+
if (
1621+
data.status === constants.challengeStatuses.Draft &&
1622+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
1623+
) {
16181624
try {
16191625
await helper.updateSelfServiceProjectInfo(
16201626
projectId,
@@ -1648,7 +1654,8 @@ async function updateChallenge(currentUser, challengeId, data) {
16481654
// if activating a challenge, the challenge must have a billing account id
16491655
if (
16501656
(!billingAccountId || billingAccountId === null) &&
1651-
challenge.status === constants.challengeStatuses.Draft
1657+
challenge.status === constants.challengeStatuses.Draft &&
1658+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
16521659
) {
16531660
throw new errors.BadRequestError(
16541661
"Cannot Activate this project, it has no active billing account."

0 commit comments

Comments
 (0)