@@ -941,7 +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 ( ! challenge . projectId ) {
944
+ if ( ! challenge . projectId && challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId ) ) {
945
945
const selfServiceProjectName = `Self service - ${ currentUser . handle } - ${ challenge . name } ` ;
946
946
challenge . projectId = await helper . createSelfServiceProject (
947
947
selfServiceProjectName ,
@@ -963,14 +963,18 @@ async function createChallenge(currentUser, challenge, userToken) {
963
963
}
964
964
965
965
/** Ensure project exists, and set direct project id, billing account id & markup */
966
- const { projectId } = challenge ;
966
+ if ( challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId ) ) {
967
+ const { projectId } = challenge ;
967
968
968
- const { directProjectId } = await projectHelper . getProject ( projectId , currentUser ) ;
969
- const { billingAccountId, markup } = await projectHelper . getProjectBillingInformation ( projectId ) ;
969
+ const { directProjectId } = await projectHelper . getProject ( projectId , currentUser ) ;
970
+ const { billingAccountId, markup } = await projectHelper . getProjectBillingInformation (
971
+ projectId
972
+ ) ;
970
973
971
- _ . set ( challenge , "legacy.directProjectId" , directProjectId ) ;
972
- _ . set ( challenge , "billing.billingAccountId" , billingAccountId ) ;
973
- _ . set ( challenge , "billing.markup" , markup || 0 ) ;
974
+ _ . set ( challenge , "legacy.directProjectId" , directProjectId ) ;
975
+ _ . set ( challenge , "billing.billingAccountId" , billingAccountId ) ;
976
+ _ . set ( challenge , "billing.markup" , markup || 0 ) ;
977
+ }
974
978
975
979
if ( ! _ . isUndefined ( _ . get ( challenge , "legacy.reviewType" ) ) ) {
976
980
_ . set ( challenge , "legacy.reviewType" , _ . toUpper ( _ . get ( challenge , "legacy.reviewType" ) ) ) ;
@@ -1516,19 +1520,22 @@ async function updateChallenge(currentUser, challengeId, data) {
1516
1520
convertPrizeSetValuesToDollars ( challenge . prizeSets , challenge . overview ) ;
1517
1521
}
1518
1522
1519
- const projectId = _ . get ( challenge , "projectId" ) ;
1523
+ let projectId , billingAccountId , markup ;
1524
+ if ( challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId ) ) {
1525
+ projectId = _ . get ( challenge , "projectId" ) ;
1520
1526
1521
- const { billingAccountId, markup } = await projectHelper . getProjectBillingInformation ( projectId ) ;
1527
+ ( { billingAccountId, markup } = await projectHelper . getProjectBillingInformation ( projectId ) ) ;
1522
1528
1523
- if ( billingAccountId && _ . isUndefined ( _ . get ( challenge , "billing.billingAccountId" ) ) ) {
1524
- _ . set ( data , "billing.billingAccountId" , billingAccountId ) ;
1525
- _ . set ( data , "billing.markup" , markup || 0 ) ;
1526
- }
1529
+ if ( billingAccountId && _ . isUndefined ( _ . get ( challenge , "billing.billingAccountId" ) ) ) {
1530
+ _ . set ( data , "billing.billingAccountId" , billingAccountId ) ;
1531
+ _ . set ( data , "billing.markup" , markup || 0 ) ;
1532
+ }
1527
1533
1528
- // Make sure the user cannot change the direct project ID
1529
- if ( data . legacy ) {
1530
- data . legacy = _ . assign ( { } , challenge . legacy , data . legacy ) ;
1531
- _ . set ( data , "legacy.directProjectId" , challenge . legacy . directProjectId ) ;
1534
+ // Make sure the user cannot change the direct project ID
1535
+ if ( data . legacy ) {
1536
+ data . legacy = _ . assign ( { } , challenge . legacy , data . legacy ) ;
1537
+ _ . set ( data , "legacy.directProjectId" , challenge . legacy . directProjectId ) ;
1538
+ }
1532
1539
}
1533
1540
1534
1541
// Remove fields from data that are not allowed to be updated and that match the existing challenge
@@ -1571,7 +1578,8 @@ async function updateChallenge(currentUser, challengeId, data) {
1571
1578
if (
1572
1579
( data . status === constants . challengeStatuses . Approved ||
1573
1580
data . status === constants . challengeStatuses . Active ) &&
1574
- challenge . status !== constants . challengeStatuses . Active
1581
+ challenge . status !== constants . challengeStatuses . Active &&
1582
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1575
1583
) {
1576
1584
try {
1577
1585
const selfServiceProjectName = `Self service - ${ challenge . createdBy } - ${ challenge . name } ` ;
@@ -1607,7 +1615,10 @@ async function updateChallenge(currentUser, challengeId, data) {
1607
1615
}
1608
1616
}
1609
1617
1610
- if ( data . status === constants . challengeStatuses . Draft ) {
1618
+ if (
1619
+ data . status === constants . challengeStatuses . Draft &&
1620
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1621
+ ) {
1611
1622
try {
1612
1623
await helper . updateSelfServiceProjectInfo (
1613
1624
projectId ,
@@ -1620,8 +1631,9 @@ async function updateChallenge(currentUser, challengeId, data) {
1620
1631
}
1621
1632
1622
1633
if (
1623
- data . status === constants . challengeStatuses . CancelledRequirementsInfeasible ||
1624
- data . status === constants . challengeStatuses . CancelledPaymentFailed
1634
+ ( data . status === constants . challengeStatuses . CancelledRequirementsInfeasible ||
1635
+ data . status === constants . challengeStatuses . CancelledPaymentFailed ) &&
1636
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1625
1637
) {
1626
1638
try {
1627
1639
await helper . cancelProject ( challenge . projectId , data . cancelReason , currentUser ) ;
@@ -1641,7 +1653,8 @@ async function updateChallenge(currentUser, challengeId, data) {
1641
1653
// if activating a challenge, the challenge must have a billing account id
1642
1654
if (
1643
1655
( ! billingAccountId || billingAccountId === null ) &&
1644
- challenge . status === constants . challengeStatuses . Draft
1656
+ challenge . status === constants . challengeStatuses . Draft &&
1657
+ challengeHelper . isProjectIdRequired ( challenge . timelineTemplateId )
1645
1658
) {
1646
1659
throw new errors . BadRequestError (
1647
1660
"Cannot Activate this project, it has no active billing account."
0 commit comments