@@ -941,10 +941,7 @@ async function createChallenge(currentUser, challenge, userToken) {
941
941
console . log ( "TYPE" , prizeTypeTmp ) ;
942
942
if ( challenge . legacy . selfService ) {
943
943
// 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 ) ) {
948
945
const selfServiceProjectName = `Self service - ${ currentUser . handle } - ${ challenge . name } ` ;
949
946
challenge . projectId = await helper . createSelfServiceProject (
950
947
selfServiceProjectName ,
@@ -966,7 +963,7 @@ async function createChallenge(currentUser, challenge, userToken) {
966
963
}
967
964
968
965
/** 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 ) ) {
970
967
const { projectId } = challenge ;
971
968
972
969
const { directProjectId } = await projectHelper . getProject ( projectId , currentUser ) ;
@@ -1523,13 +1520,18 @@ async function updateChallenge(currentUser, challengeId, data) {
1523
1520
convertPrizeSetValuesToDollars ( challenge . prizeSets , challenge . overview ) ;
1524
1521
}
1525
1522
1526
- const projectId = _ . get ( challenge , "projectId" ) ;
1523
+ let projectId ;
1524
+ if ( challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId ?? "" ) ) {
1525
+ projectId = _ . get ( challenge , "projectId" ) ;
1527
1526
1528
- const { billingAccountId, markup } = await projectHelper . getProjectBillingInformation ( projectId ) ;
1527
+ const { billingAccountId, markup } = await projectHelper . getProjectBillingInformation (
1528
+ projectId
1529
+ ) ;
1529
1530
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
+ }
1533
1535
}
1534
1536
1535
1537
// Make sure the user cannot change the direct project ID
@@ -1578,7 +1580,8 @@ async function updateChallenge(currentUser, challengeId, data) {
1578
1580
if (
1579
1581
( data . status === constants . challengeStatuses . Approved ||
1580
1582
data . status === constants . challengeStatuses . Active ) &&
1581
- challenge . status !== constants . challengeStatuses . Active
1583
+ challenge . status !== constants . challengeStatuses . Active &&
1584
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1582
1585
) {
1583
1586
try {
1584
1587
const selfServiceProjectName = `Self service - ${ challenge . createdBy } - ${ challenge . name } ` ;
@@ -1614,7 +1617,10 @@ async function updateChallenge(currentUser, challengeId, data) {
1614
1617
}
1615
1618
}
1616
1619
1617
- if ( data . status === constants . challengeStatuses . Draft ) {
1620
+ if (
1621
+ data . status === constants . challengeStatuses . Draft &&
1622
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1623
+ ) {
1618
1624
try {
1619
1625
await helper . updateSelfServiceProjectInfo (
1620
1626
projectId ,
@@ -1648,7 +1654,8 @@ async function updateChallenge(currentUser, challengeId, data) {
1648
1654
// if activating a challenge, the challenge must have a billing account id
1649
1655
if (
1650
1656
( ! billingAccountId || billingAccountId === null ) &&
1651
- challenge . status === constants . challengeStatuses . Draft
1657
+ challenge . status === constants . challengeStatuses . Draft &&
1658
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1652
1659
) {
1653
1660
throw new errors . BadRequestError (
1654
1661
"Cannot Activate this project, it has no active billing account."
0 commit comments