@@ -645,15 +645,20 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
645
645
helper . ensureNoDuplicateOrNullElements ( data . groups , 'groups' )
646
646
helper . ensureNoDuplicateOrNullElements ( data . gitRepoURLs , 'gitRepoURLs' )
647
647
648
+ console . log ( 'Before fetching challenge' )
648
649
const challenge = await helper . getById ( 'Challenge' , challengeId )
649
-
650
+ console . log ( 'After fetching challenge' )
650
651
// check groups authorization
652
+ console . log ( 'Before checking group access' )
651
653
await ensureAccessibleByGroupsAccess ( currentUser , challenge )
654
+ console . log ( 'After checking group access' )
652
655
656
+ console . log ( 'before fetching attachments' )
653
657
let newAttachments
654
658
if ( isFull || ! _ . isUndefined ( data . attachmentIds ) ) {
655
659
newAttachments = await helper . getByIds ( 'Attachment' , data . attachmentIds || [ ] )
656
660
}
661
+ console . log ( 'after fetching attachments' )
657
662
658
663
if ( ! currentUser . isMachine && ! helper . hasAdminRole ( currentUser ) && challenge . createdBy . toLowerCase ( ) !== currentUser . handle . toLowerCase ( ) ) {
659
664
throw new errors . ForbiddenError ( `Only M2M, admin or challenge's copilot can perform modification.` )
@@ -669,26 +674,33 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
669
674
} )
670
675
}
671
676
677
+ console . log ( 'before validateChallengeData(data)' )
672
678
await validateChallengeData ( data )
673
679
if ( ( challenge . status === constants . challengeStatuses . Completed || challenge . status === constants . challengeStatuses . Canceled ) && data . status && data . status !== challenge . status ) {
674
680
throw new errors . BadRequestError ( `Cannot change ${ challenge . status } challenge status to ${ data . status } status` )
675
681
}
682
+ console . log ( 'after validateChallengeData(data)' )
676
683
677
684
if ( data . winners && ( challenge . status !== constants . challengeStatuses . Completed && data . status !== constants . challengeStatuses . Completed ) ) {
678
685
throw new errors . BadRequestError ( `Cannot set winners for challenge with non-completed ${ challenge . status } status` )
679
686
}
680
687
688
+ console . log ( 'before validatePhases(data.phases)' )
681
689
if ( data . phases ) {
682
690
await helper . validatePhases ( data . phases )
683
691
// populate phases
684
692
await populatePhases ( data . phases , data . startDate || challenge . startDate , data . timelineTemplateId || challenge . timelineTemplateId )
685
693
data . endDate = helper . calculateChallengeEndDate ( challenge , data )
686
694
}
695
+ console . log ( 'after validatePhases(data.phases)' )
687
696
697
+ console . log ( 'before validateWinners(data.winners)' )
688
698
if ( data . winners && data . winners . length ) {
689
699
await validateWinners ( data . winners )
690
700
}
701
+ console . log ( 'after validateWinners(data.winners)' )
691
702
703
+ console . log ( 'before constructing the query' )
692
704
data . updated = new Date ( )
693
705
data . updatedBy = currentUser . handle || currentUser . sub
694
706
const updateDetails = { }
@@ -884,15 +896,17 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
884
896
// send null to Elasticsearch to clear the field
885
897
data . winners = null
886
898
}
899
+ console . log ( 'after constructing the query' )
887
900
888
- console . log ( '------------------' )
889
- console . log ( updateDetails )
890
- console . log ( '------------------' )
891
-
901
+ console . log ( 'before update' )
892
902
await models . Challenge . update ( { id : challengeId } , updateDetails )
903
+ console . log ( 'after update' )
904
+ console . log ( 'before creating audit log' )
905
+
893
906
if ( auditLogs . length > 0 ) {
894
907
await models . AuditLog . batchPut ( auditLogs )
895
908
}
909
+ console . log ( 'after creating audit log' )
896
910
897
911
delete data . attachmentIds
898
912
_ . assign ( challenge , data )
0 commit comments