@@ -1869,15 +1869,15 @@ async function updateChallenge(currentUser, challengeId, data) {
1869
1869
`Post Bus Event: ${ constants . Topics . ChallengeUpdated } ${ JSON . stringify ( updatedChallenge ) } `
1870
1870
) ;
1871
1871
1872
+ enrichChallengeForResponse ( updatedChallenge , track , type ) ;
1873
+
1872
1874
await helper . postBusEvent ( constants . Topics . ChallengeUpdated , updatedChallenge , {
1873
1875
key :
1874
1876
updatedChallenge . status === "Completed"
1875
1877
? `${ updatedChallenge . id } :${ updatedChallenge . status } `
1876
1878
: undefined ,
1877
1879
} ) ;
1878
1880
1879
- enrichChallengeForResponse ( updatedChallenge , track , type ) ;
1880
-
1881
1881
// Update ES
1882
1882
// TODO: Uncomment
1883
1883
await esClient . update ( {
@@ -1964,12 +1964,14 @@ updateChallenge.schema = {
1964
1964
selfServiceCopilot : Joi . string ( ) . allow ( null ) ,
1965
1965
} )
1966
1966
. unknown ( true ) ,
1967
- cancelReason : Joi . string ( ) ,
1968
- task : Joi . object ( ) . keys ( {
1969
- isTask : Joi . boolean ( ) . default ( false ) ,
1970
- isAssigned : Joi . boolean ( ) . default ( false ) ,
1971
- memberId : Joi . alternatives ( ) . try ( Joi . string ( ) . allow ( null ) , Joi . number ( ) . allow ( null ) ) ,
1972
- } ) ,
1967
+ cancelReason : Joi . string ( ) . optional ( ) ,
1968
+ task : Joi . object ( )
1969
+ . keys ( {
1970
+ isTask : Joi . boolean ( ) . default ( false ) ,
1971
+ isAssigned : Joi . boolean ( ) . default ( false ) ,
1972
+ memberId : Joi . alternatives ( ) . try ( Joi . string ( ) . allow ( null ) , Joi . number ( ) . allow ( null ) ) ,
1973
+ } )
1974
+ . optional ( ) ,
1973
1975
billing : Joi . object ( )
1974
1976
. keys ( {
1975
1977
billingAccountId : Joi . string ( ) ,
@@ -1978,10 +1980,10 @@ updateChallenge.schema = {
1978
1980
. unknown ( true ) ,
1979
1981
trackId : Joi . optionalId ( ) ,
1980
1982
typeId : Joi . optionalId ( ) ,
1981
- name : Joi . string ( ) ,
1982
- description : Joi . string ( ) ,
1983
- privateDescription : Joi . string ( ) ,
1984
- descriptionFormat : Joi . string ( ) ,
1983
+ name : Joi . string ( ) . optional ( ) ,
1984
+ description : Joi . string ( ) . optional ( ) ,
1985
+ privateDescription : Joi . string ( ) . optional ( ) ,
1986
+ descriptionFormat : Joi . string ( ) . optional ( ) ,
1985
1987
metadata : Joi . array ( )
1986
1988
. items (
1987
1989
Joi . object ( )
@@ -1992,7 +1994,7 @@ updateChallenge.schema = {
1992
1994
. unknown ( true )
1993
1995
)
1994
1996
. unique ( ( a , b ) => a . name === b . name ) ,
1995
- timelineTemplateId : Joi . string ( ) , // changing this to update migrated challenges
1997
+ timelineTemplateId : Joi . string ( ) . optional ( ) , // changing this to update migrated challenges
1996
1998
phases : Joi . array ( )
1997
1999
. items (
1998
2000
Joi . object ( )
@@ -2015,7 +2017,8 @@ updateChallenge.schema = {
2015
2017
} )
2016
2018
. unknown ( true )
2017
2019
)
2018
- . min ( 1 ) ,
2020
+ . min ( 1 )
2021
+ . optional ( ) ,
2019
2022
events : Joi . array ( ) . items (
2020
2023
Joi . object ( )
2021
2024
. keys ( {
@@ -2024,17 +2027,20 @@ updateChallenge.schema = {
2024
2027
key : Joi . string ( ) ,
2025
2028
} )
2026
2029
. unknown ( true )
2030
+ . optional ( )
2027
2031
) ,
2028
- discussions : Joi . array ( ) . items (
2029
- Joi . object ( ) . keys ( {
2030
- id : Joi . optionalId ( ) ,
2031
- name : Joi . string ( ) . required ( ) ,
2032
- type : Joi . string ( ) . required ( ) . valid ( _ . values ( constants . DiscussionTypes ) ) ,
2033
- provider : Joi . string ( ) . required ( ) ,
2034
- url : Joi . string ( ) ,
2035
- options : Joi . array ( ) . items ( Joi . object ( ) ) ,
2036
- } )
2037
- ) ,
2032
+ discussions : Joi . array ( )
2033
+ . items (
2034
+ Joi . object ( ) . keys ( {
2035
+ id : Joi . optionalId ( ) ,
2036
+ name : Joi . string ( ) . required ( ) ,
2037
+ type : Joi . string ( ) . required ( ) . valid ( _ . values ( constants . DiscussionTypes ) ) ,
2038
+ provider : Joi . string ( ) . required ( ) ,
2039
+ url : Joi . string ( ) ,
2040
+ options : Joi . array ( ) . items ( Joi . object ( ) ) ,
2041
+ } )
2042
+ )
2043
+ . optional ( ) ,
2038
2044
startDate : Joi . date ( ) ,
2039
2045
prizeSets : Joi . array ( )
2040
2046
. items (
@@ -2085,7 +2091,7 @@ updateChallenge.schema = {
2085
2091
} )
2086
2092
. unknown ( true )
2087
2093
)
2088
- . min ( 1 ) ,
2094
+ . optional ( ) ,
2089
2095
terms : Joi . array ( ) . items (
2090
2096
Joi . object ( ) . keys ( {
2091
2097
id : Joi . id ( ) ,
@@ -2198,10 +2204,12 @@ function sanitizeChallenge(challenge) {
2198
2204
if ( challenge . events ) {
2199
2205
sanitized . events = _ . map ( challenge . events , ( event ) => _ . pick ( event , [ "id" , "name" , "key" ] ) ) ;
2200
2206
}
2201
- if ( challenge . winners ) {
2207
+ if ( challenge . legacy != null && challenge . legacy . pureV5Task === true && challenge . winners ) {
2202
2208
sanitized . winners = _ . map ( challenge . winners , ( winner ) =>
2203
2209
_ . pick ( winner , [ "userId" , "handle" , "placement" , "type" ] )
2204
2210
) ;
2211
+ } else {
2212
+ delete challenge . winners ;
2205
2213
}
2206
2214
if ( challenge . discussions ) {
2207
2215
sanitized . discussions = _ . map ( challenge . discussions , ( discussion ) => ( {
@@ -2219,12 +2227,6 @@ function sanitizeChallenge(challenge) {
2219
2227
}
2220
2228
return sanitized ;
2221
2229
}
2222
- /*
2223
- metadata = [ { }, { }, { }] -> in database
2224
- metadata = [ {} ]
2225
-
2226
- final state: [ {} ]
2227
- */
2228
2230
2229
2231
function sanitizeData ( data , challenge ) {
2230
2232
for ( const key in data ) {
0 commit comments