@@ -410,7 +410,9 @@ async function populatePhases (phases, startDate, timelineTemplateId) {
410
410
async function createChallenge ( currentUser , challenge , userToken ) {
411
411
await helper . ensureProjectExist ( challenge . projectId , userToken )
412
412
await validateChallengeData ( challenge )
413
- await helper . validatePhases ( challenge . phases )
413
+ if ( challenge . phases && challenge . phases . length > 0 ) {
414
+ await helper . validatePhases ( challenge . phases )
415
+ }
414
416
helper . ensureNoDuplicateOrNullElements ( challenge . tags , 'tags' )
415
417
helper . ensureNoDuplicateOrNullElements ( challenge . groups , 'groups' )
416
418
helper . ensureNoDuplicateOrNullElements ( challenge . terms , 'terms' )
@@ -419,13 +421,17 @@ async function createChallenge (currentUser, challenge, userToken) {
419
421
await ensureAccessibleByGroupsAccess ( currentUser , challenge )
420
422
421
423
// populate phases
422
- await populatePhases ( challenge . phases , challenge . startDate , challenge . timelineTemplateId )
424
+ if ( challenge . timelineTemplateId && challenge . phases && challenge . phases . length > 0 ) {
425
+ await populatePhases ( challenge . phases , challenge . startDate , challenge . timelineTemplateId )
426
+ }
423
427
424
428
// populate challenge terms
425
429
const projectTerms = await helper . getProjectDefaultTerms ( challenge . projectId )
426
430
challenge . terms = await helper . getChallengeTerms ( _ . union ( projectTerms , challenge . terms ) )
427
431
428
- challenge . endDate = helper . calculateChallengeEndDate ( challenge )
432
+ if ( challenge . phases && challenge . phases . length > 0 ) {
433
+ challenge . endDate = helper . calculateChallengeEndDate ( challenge )
434
+ }
429
435
const ret = await helper . create ( 'Challenge' , _ . assign ( {
430
436
id : uuid ( ) ,
431
437
created : new Date ( ) ,
@@ -450,26 +456,26 @@ async function createChallenge (currentUser, challenge, userToken) {
450
456
createChallenge . schema = {
451
457
currentUser : Joi . any ( ) ,
452
458
challenge : Joi . object ( ) . keys ( {
453
- typeId : Joi . id ( ) ,
459
+ typeId : Joi . optionalId ( ) ,
454
460
legacy : Joi . object ( ) . keys ( {
455
461
track : Joi . string ( ) . required ( ) ,
456
462
reviewType : Joi . string ( ) . required ( ) ,
457
463
confidentialityType : Joi . string ( ) . default ( config . DEFAULT_CONFIDENTIALITY_TYPE ) ,
458
464
forumId : Joi . number ( ) . integer ( ) . positive ( ) ,
459
465
informixModified : Joi . string ( )
460
- } ) . required ( ) ,
466
+ } ) ,
461
467
name : Joi . string ( ) . required ( ) ,
462
- description : Joi . string ( ) . required ( ) ,
468
+ description : Joi . string ( ) ,
463
469
privateDescription : Joi . string ( ) ,
464
470
metadata : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
465
471
name : Joi . id ( ) ,
466
472
value : Joi . string ( ) . required ( )
467
473
} ) ) . unique ( ( a , b ) => a . type === b . type ) ,
468
- timelineTemplateId : Joi . id ( ) ,
474
+ timelineTemplateId : Joi . optionalId ( ) ,
469
475
phases : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
470
476
phaseId : Joi . id ( ) ,
471
477
duration : Joi . number ( ) . positive ( )
472
- } ) ) . min ( 1 ) . required ( ) ,
478
+ } ) ) ,
473
479
prizeSets : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
474
480
type : Joi . string ( ) . valid ( _ . values ( constants . prizeSetTypes ) ) . required ( ) ,
475
481
description : Joi . string ( ) ,
@@ -478,11 +484,11 @@ createChallenge.schema = {
478
484
type : Joi . string ( ) . required ( ) ,
479
485
value : Joi . number ( ) . positive ( ) . required ( )
480
486
} ) ) . min ( 1 ) . required ( )
481
- } ) ) . min ( 1 ) . required ( ) ,
482
- tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) . min ( 1 ) . required ( ) , // tag names
487
+ } ) ) ,
488
+ tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) , // tag names
483
489
projectId : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
484
490
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
485
- startDate : Joi . date ( ) . required ( ) ,
491
+ startDate : Joi . date ( ) ,
486
492
status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) . required ( ) ,
487
493
groups : Joi . array ( ) . items ( Joi . string ( ) ) , // group names
488
494
gitRepoURLs : Joi . array ( ) . items ( Joi . string ( ) . uri ( ) ) ,
@@ -531,13 +537,15 @@ async function getChallenge (currentUser, id) {
531
537
await ensureAccessibleByGroupsAccess ( currentUser , challenge )
532
538
// FIXME: Temporarily hard coded as the migrad
533
539
// populate type property based on the typeId
534
- try {
535
- const type = await helper . getById ( 'ChallengeType' , challenge . typeId )
536
- challenge . type = type . name
537
- } catch ( e ) {
538
- challenge . typeId = '45415132-79fa-4d13-a9ac-71f50020dc10'
539
- const type = await helper . getById ( 'ChallengeType' , challenge . typeId )
540
- challenge . type = type . name
540
+ if ( challenge . typeId ) {
541
+ try {
542
+ const type = await helper . getById ( 'ChallengeType' , challenge . typeId )
543
+ challenge . type = type . name
544
+ } catch ( e ) {
545
+ challenge . typeId = '45415132-79fa-4d13-a9ac-71f50020dc10'
546
+ const type = await helper . getById ( 'ChallengeType' , challenge . typeId )
547
+ challenge . type = type . name
548
+ }
541
549
}
542
550
// delete challenge.typeId
543
551
@@ -553,7 +561,9 @@ async function getChallenge (currentUser, id) {
553
561
_ . unset ( challenge , 'privateDescription' )
554
562
}
555
563
556
- getPhasesAndPopulate ( challenge )
564
+ if ( challenge . phases && challenge . phases . length > 0 ) {
565
+ getPhasesAndPopulate ( challenge )
566
+ }
557
567
558
568
return challenge
559
569
}
@@ -569,7 +579,7 @@ getChallenge.schema = {
569
579
* @param {Array } otherPhases the second phases array
570
580
* @returns {Boolean } true if different, false otherwise
571
581
*/
572
- function isDifferentPhases ( phases , otherPhases ) {
582
+ function isDifferentPhases ( phases = [ ] , otherPhases ) {
573
583
if ( phases . length !== otherPhases . length ) {
574
584
return true
575
585
} else {
@@ -619,7 +629,7 @@ function isSamePrizeArray (prizes, otherPrizes) {
619
629
* @param {Array } otherPrizeSets the second PrizeSet Array
620
630
* @returns {Boolean } true if different, false otherwise
621
631
*/
622
- function isDifferentPrizeSets ( prizeSets , otherPrizeSets ) {
632
+ function isDifferentPrizeSets ( prizeSets = [ ] , otherPrizeSets ) {
623
633
const length = otherPrizeSets . length
624
634
if ( prizeSets . length === otherPrizeSets . length ) {
625
635
let used = Array ( length ) . fill ( false )
@@ -1019,20 +1029,20 @@ fullyUpdateChallenge.schema = {
1019
1029
directProjectId : Joi . number ( ) ,
1020
1030
forumId : Joi . number ( ) . integer ( ) . positive ( ) ,
1021
1031
informixModified : Joi . string ( )
1022
- } ) . required ( ) ,
1023
- typeId : Joi . id ( ) ,
1032
+ } ) ,
1033
+ typeId : Joi . optionalId ( ) ,
1024
1034
name : Joi . string ( ) . required ( ) ,
1025
- description : Joi . string ( ) . required ( ) ,
1035
+ description : Joi . string ( ) ,
1026
1036
privateDescription : Joi . string ( ) ,
1027
1037
metadata : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
1028
1038
name : Joi . id ( ) ,
1029
1039
value : Joi . string ( ) . required ( )
1030
1040
} ) ) . unique ( ( a , b ) => a . type === b . type ) ,
1031
- timelineTemplateId : Joi . id ( ) ,
1041
+ timelineTemplateId : Joi . optionalId ( ) ,
1032
1042
phases : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
1033
1043
phaseId : Joi . id ( ) ,
1034
1044
duration : Joi . number ( ) . positive ( )
1035
- } ) ) . min ( 1 ) . required ( ) ,
1045
+ } ) ) ,
1036
1046
prizeSets : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
1037
1047
type : Joi . string ( ) . valid ( _ . values ( constants . prizeSetTypes ) ) . required ( ) ,
1038
1048
description : Joi . string ( ) ,
@@ -1041,8 +1051,8 @@ fullyUpdateChallenge.schema = {
1041
1051
type : Joi . string ( ) . required ( ) ,
1042
1052
value : Joi . number ( ) . positive ( ) . required ( )
1043
1053
} ) ) . min ( 1 ) . required ( )
1044
- } ) ) . min ( 1 ) . required ( ) ,
1045
- tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) . min ( 1 ) . required ( ) , // tag names
1054
+ } ) ) ,
1055
+ tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) , // tag names
1046
1056
projectId : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
1047
1057
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
1048
1058
startDate : Joi . date ( ) ,
0 commit comments