Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 53da312

Browse files
authored
Merge pull request #102 from topcoder-platform/multi-round-sync
Add in phase dependencies test
2 parents bb10113 + e6a6f6e commit 53da312

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/services/timelineService.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const QUERY_GET_TIMELINE_NOTIFICATION_SETTINGS = 'SELECT value FROM project_info
2525
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)'
2626
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 = ?'
2727

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 = ?'
2830
/**
2931
* Formats a date into a format supported by ifx
3032
* @param {String} dateStr the date in string format
@@ -64,6 +66,38 @@ async function getPhaseTypes () {
6466
return result
6567
}
6668

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+
}
67101
/**
68102
* Drop challenge phase
69103
* @param {Number} challengeLegacyId the legacy challenge ID
@@ -150,6 +184,19 @@ async function createPhase (challengeLegacyId, phaseTypeId, statusTypeId, schedu
150184
createdBy
151185
])
152186
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+
}
153200
} catch (e) {
154201
logger.error(`Error in 'createPhase' ${e}, rolling back transaction`)
155202
await connection.rollbackTransactionAsync()

0 commit comments

Comments
 (0)