@@ -78,6 +78,9 @@ async function searchChallenges (currentUser, criteria) {
7878 if ( criteria . group ) {
7979 boolQuery . push ( { match_phrase : { groups : criteria . group } } )
8080 }
81+ if ( criteria . gitRepoURL ) {
82+ boolQuery . push ( { match_phrase : { gitRepoURLs : criteria . gitRepoURL } } )
83+ }
8184 if ( criteria . createdDateStart ) {
8285 boolQuery . push ( { range : { created : { gte : criteria . createdDateStart } } } )
8386 }
@@ -144,6 +147,7 @@ searchChallenges.schema = {
144147 legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
145148 status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) ,
146149 group : Joi . string ( ) ,
150+ gitRepoURL : Joi . string ( ) . uri ( ) ,
147151 createdDateStart : Joi . date ( ) ,
148152 createdDateEnd : Joi . date ( ) ,
149153 updatedDateStart : Joi . date ( ) ,
@@ -259,7 +263,8 @@ createChallenge.schema = {
259263 forumId : Joi . number ( ) . integer ( ) . positive ( ) ,
260264 startDate : Joi . date ( ) . required ( ) ,
261265 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 ( ) )
263268 } ) . required ( ) ,
264269 userToken : Joi . any ( )
265270}
@@ -426,6 +431,7 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
426431 helper . ensureNoDuplicateOrNullElements ( data . tags , 'tags' )
427432 helper . ensureNoDuplicateOrNullElements ( data . attachmentIds , 'attachmentIds' )
428433 helper . ensureNoDuplicateOrNullElements ( data . groups , 'groups' )
434+ helper . ensureNoDuplicateOrNullElements ( data . gitRepoURLs , 'gitRepoURLs' )
429435
430436 const challenge = await helper . getById ( 'Challenge' , challengeId )
431437
@@ -493,6 +499,11 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
493499 _ . intersection ( challenge [ key ] , value ) . length !== value . length ) {
494500 op = '$PUT'
495501 }
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+ }
496507 } else if ( _ . isUndefined ( challenge [ key ] ) || challenge [ key ] !== value ) {
497508 op = '$PUT'
498509 }
@@ -580,6 +591,24 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
580591 // send null to Elasticsearch to clear the field
581592 data . groups = null
582593 }
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+ }
583612 if ( isFull && _ . isUndefined ( data . legacyId ) && challenge . legacyId ) {
584613 if ( ! updateDetails [ '$DELETE' ] ) {
585614 updateDetails [ '$DELETE' ] = { }
@@ -730,7 +759,8 @@ partiallyUpdateChallenge.schema = {
730759 legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
731760 status : Joi . string ( ) . valid ( _ . values ( constants . challengeStatuses ) ) ,
732761 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 ( ) )
734764 } ) . required ( ) ,
735765 userToken : Joi . any ( )
736766}
0 commit comments