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