@@ -78,6 +78,9 @@ async function searchChallenges (currentUser, criteria) {
78
78
if ( criteria . group ) {
79
79
boolQuery . push ( { match_phrase : { groups : criteria . group } } )
80
80
}
81
+ if ( criteria . gitRepoURL ) {
82
+ boolQuery . push ( { match_phrase : { gitRepoURLs : criteria . gitRepoURL } } )
83
+ }
81
84
if ( criteria . createdDateStart ) {
82
85
boolQuery . push ( { range : { created : { gte : criteria . createdDateStart } } } )
83
86
}
@@ -144,6 +147,7 @@ searchChallenges.schema = {
144
147
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
145
148
status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) ,
146
149
group : Joi . string ( ) ,
150
+ gitRepoURL : Joi . string ( ) . uri ( ) ,
147
151
createdDateStart : Joi . date ( ) ,
148
152
createdDateEnd : Joi . date ( ) ,
149
153
updatedDateStart : Joi . date ( ) ,
@@ -259,7 +263,8 @@ createChallenge.schema = {
259
263
forumId : Joi . number ( ) . integer ( ) . positive ( ) ,
260
264
startDate : Joi . date ( ) . required ( ) ,
261
265
status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) . required ( ) ,
262
- groups : Joi . array ( ) . items ( Joi . string ( ) ) // group names
266
+ groups : Joi . array ( ) . items ( Joi . string ( ) ) , // group names
267
+ gitRepoURLs : Joi . array ( ) . items ( Joi . string ( ) . uri ( ) )
263
268
} ) . required ( ) ,
264
269
userToken : Joi . any ( )
265
270
}
@@ -426,6 +431,7 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
426
431
helper . ensureNoDuplicateOrNullElements ( data . tags , 'tags' )
427
432
helper . ensureNoDuplicateOrNullElements ( data . attachmentIds , 'attachmentIds' )
428
433
helper . ensureNoDuplicateOrNullElements ( data . groups , 'groups' )
434
+ helper . ensureNoDuplicateOrNullElements ( data . gitRepoURLs , 'gitRepoURLs' )
429
435
430
436
const challenge = await helper . getById ( 'Challenge' , challengeId )
431
437
@@ -493,6 +499,11 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
493
499
_ . intersection ( challenge [ key ] , value ) . length !== value . length ) {
494
500
op = '$PUT'
495
501
}
502
+ } else if ( key === 'gitRepoURLs' ) {
503
+ if ( _ . isUndefined ( challenge [ key ] ) || challenge [ key ] . length !== value . length ||
504
+ _ . intersection ( challenge [ key ] , value ) . length !== value . length ) {
505
+ op = '$PUT'
506
+ }
496
507
} else if ( _ . isUndefined ( challenge [ key ] ) || challenge [ key ] !== value ) {
497
508
op = '$PUT'
498
509
}
@@ -580,6 +591,24 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
580
591
// send null to Elasticsearch to clear the field
581
592
data . groups = null
582
593
}
594
+ if ( isFull && _ . isUndefined ( data . gitRepoURLs ) && challenge . gitRepoURLs ) {
595
+ if ( ! updateDetails [ '$DELETE' ] ) {
596
+ updateDetails [ '$DELETE' ] = { }
597
+ }
598
+ updateDetails [ '$DELETE' ] . gitRepoURLs = null
599
+ auditLogs . push ( {
600
+ id : uuid ( ) ,
601
+ challengeId,
602
+ fieldName : 'gitRepoURLs' ,
603
+ oldValue : JSON . stringify ( challenge . gitRepoURLs ) ,
604
+ newValue : 'NULL' ,
605
+ created : new Date ( ) ,
606
+ createdBy : currentUser . handle || currentUser . sub
607
+ } )
608
+ delete challenge . gitRepoURLs
609
+ // send null to Elasticsearch to clear the field
610
+ data . gitRepoURLs = null
611
+ }
583
612
if ( isFull && _ . isUndefined ( data . legacyId ) && challenge . legacyId ) {
584
613
if ( ! updateDetails [ '$DELETE' ] ) {
585
614
updateDetails [ '$DELETE' ] = { }
@@ -730,7 +759,8 @@ partiallyUpdateChallenge.schema = {
730
759
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
731
760
status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) ,
732
761
attachmentIds : Joi . array ( ) . items ( Joi . optionalId ( ) ) ,
733
- groups : Joi . array ( ) . items ( Joi . string ( ) ) // group names
762
+ groups : Joi . array ( ) . items ( Joi . string ( ) ) , // group names
763
+ gitRepoURLs : Joi . array ( ) . items ( Joi . string ( ) . uri ( ) )
734
764
} ) . required ( ) ,
735
765
userToken : Joi . any ( )
736
766
}
0 commit comments