@@ -25,6 +25,8 @@ const QUERY_GET_TIMELINE_NOTIFICATION_SETTINGS = 'SELECT value FROM project_info
25
25
const QUERY_CREATE_TIMELINE_NOTIFICATIONS = 'INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (?, "11", "On", ?, CURRENT, ?, CURRENT)'
26
26
const QUERY_UPDATE_TIMELINE_NOTIFICATIONS = 'UPDATE project_info SET value = "On", modify_user = ?, modify_date = CURRENT WHERE project_info_type_id = "11" AND project_id = ?'
27
27
28
+ const QUERY_INSERT_CHALLENGE_PHASE_DEPENDENCY = 'INSERT INTO phase_dependency (dependency_phase_id, dependent_phase_id, dependency_start, dependent_start, lag_time, create_user, create_date, modify_user, modify_date) VALUES (?, ?, ?, 1, 0, ?, CURRENT, ?, CURRENT)'
29
+ const QUERY_GET_PROJECT_PHASE_ID = 'SELECT project_phase_id FROM project_phase WHERE project_id = ? AND phase_type_id = ?'
28
30
/**
29
31
* Formats a date into a format supported by ifx
30
32
* @param {String } dateStr the date in string format
@@ -64,6 +66,38 @@ async function getPhaseTypes () {
64
66
return result
65
67
}
66
68
69
+ async function insertPhaseDependency ( dependencyPhaseId , dependentPhaseId , dependencyStart , createdBy ) {
70
+ const connection = await helper . getInformixConnection ( )
71
+ let result = null
72
+ try {
73
+ let query = await prepare ( connection , QUERY_INSERT_CHALLENGE_PHASE_DEPENDENCY )
74
+ result = await query . executeAsync ( [ dependencyPhaseId , dependentPhaseId , dependencyStart , createdBy , createdBy ] )
75
+ } catch ( e ) {
76
+ logger . error ( `Error in 'insertPhaseDependency' ${ e } ` )
77
+ throw e
78
+ } finally {
79
+ await connection . closeAsync ( )
80
+ }
81
+ return result
82
+ }
83
+ /**
84
+ * Gets phase for the given phase type for the given challenge ID
85
+ */
86
+ async function getProjectPhaseId ( challengeLegacyId , phaseTypeId ) {
87
+ const connection = await helper . getInformixConnection ( )
88
+ let result = null
89
+ try {
90
+ await connection . beginTransactionAsync ( )
91
+ let query = await prepare ( connection , QUERY_GET_PROJECT_PHASE_ID )
92
+ result = await query . executeAsync ( [ challengeLegacyId , phaseTypeId ] )
93
+ } catch ( e ) {
94
+ logger . error ( `Error in 'getProjectPhaseId' ${ e } ` )
95
+ throw e
96
+ } finally {
97
+ await connection . closeAsync ( )
98
+ }
99
+ return result
100
+ }
67
101
/**
68
102
* Drop challenge phase
69
103
* @param {Number } challengeLegacyId the legacy challenge ID
@@ -150,6 +184,19 @@ async function createPhase (challengeLegacyId, phaseTypeId, statusTypeId, schedu
150
184
createdBy
151
185
] )
152
186
await connection . commitTransactionAsync ( )
187
+
188
+ //Handle checkpoint phases
189
+ //Magic numbers: 15=checkpoint submission, 16=checkpoint screen, 17=checkpoint review, 1=registration
190
+ //For dependencyStart: 1=start, 0=end
191
+ if ( phaseTypeId == 17 ) {
192
+ registrationPhaseId = await this . getProjectPhaseId ( challengeLegacyId , 1 )
193
+ checkpointSubmissionPhaseId = await this . getProjectPhaseId ( challengeLegacyId , 15 )
194
+ checkpointScreeningPhaseId = await this . getProjectPhaseId ( challengeLegacyId , 16 )
195
+ checkpointReviewPhaseId = await this . getProjectPhaseId ( challengeLegacyId , 17 )
196
+ await this . insertPhaseDependency ( registrationPhaseId , checkpointSubmissionPhaseId , 1 , createdBy )
197
+ await this . insertPhaseDependency ( checkpointSubmissionPhaseId , checkpointScreeningPhaseId , 0 , createdBy )
198
+ await this . insertPhaseDependency ( checkpointScreeningPhaseId , checkpointReviewPhaseId , 0 , createdBy )
199
+ }
153
200
} catch ( e ) {
154
201
logger . error ( `Error in 'createPhase' ${ e } , rolling back transaction` )
155
202
await connection . rollbackTransactionAsync ( )
0 commit comments