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

Commit f40c11e

Browse files
split setting copilot payment into 2 phases
1 parent d2a311c commit f40c11e

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/services/ProcessorService.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ async function setCopilotPayment (challengeId, legacyChallengeId, prizeSets = []
202202
return
203203
}
204204
logger.debug(`Setting Copilot Payment: ${copilotPayment} for legacyId ${legacyChallengeId} for copilot ${copilotResource.memberId}`)
205+
if (copilotPayment !== null && copilotPayment >= 0) {
206+
await copilotPaymentService.setManualCopilotPayment(legacyChallengeId, createdBy, updatedBy)
207+
}
205208
await copilotPaymentService.setCopilotPayment(legacyChallengeId, copilotPayment, createdBy, updatedBy)
206209
}
207210
} catch (e) {

src/services/copilotPaymentService.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,49 @@ async function prepare (connection, sql) {
5050
}
5151

5252
/**
53-
* Set the copilot payment
53+
* Set manual copilot payment
5454
* @param {Number} challengeLegacyId the legacy challenge ID
55-
* @param {Number} amount the $ amount of the copilot payment
5655
* @param {String} createdBy the create user handle
5756
* @param {String} updatedBy the update user handle
5857
*/
59-
async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedBy) {
58+
async function setManualCopilotPayment (challengeLegacyId, createdBy, updatedBy) {
6059
const connection = await helper.getInformixConnection()
6160
try {
6261
await connection.beginTransactionAsync()
6362
const copilotResourceId = await getCopilotResourceId(connection, challengeLegacyId)
64-
const copilotPayment = await getCopilotPayment(connection, challengeLegacyId)
65-
if (amount != null && amount >= 0) {
63+
if (copilotResourceId) {
6664
// Make sure the payment type is set to manual
67-
// TODO: Figure out why data is not saved in IFX even when there are no errors
6865
const paymentType = await getCopilotPaymentType(connection, copilotResourceId)
6966
if (!paymentType) {
7067
await createCopilotPaymentType(connection, copilotResourceId, 'true', updatedBy || createdBy)
7168
} else if (_.toLower(_.toString(paymentType.value)) !== 'true') {
7269
await updateCopilotPaymentType(connection, copilotResourceId, 'true', updatedBy || createdBy)
7370
}
71+
}
72+
await connection.commitTransactionAsync()
73+
} catch (e) {
74+
logger.error(`Error in 'setManualCopilotPayment' ${e}`)
75+
await connection.rollbackTransactionAsync()
76+
throw e
77+
} finally {
78+
await connection.closeAsync()
79+
}
80+
}
81+
82+
/**
83+
* Set the copilot payment
84+
* @param {Number} challengeLegacyId the legacy challenge ID
85+
* @param {Number} amount the $ amount of the copilot payment
86+
* @param {String} createdBy the create user handle
87+
* @param {String} updatedBy the update user handle
88+
*/
89+
async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedBy) {
90+
const connection = await helper.getInformixConnection()
91+
try {
92+
await connection.beginTransactionAsync()
93+
const copilotResourceId = await getCopilotResourceId(connection, challengeLegacyId)
94+
const copilotPayment = await getCopilotPayment(connection, challengeLegacyId)
95+
if (amount !== null && amount >= 0) {
7496
if (copilotPayment) {
7597
logger.debug(`Copilot payment exists, updating: ${challengeLegacyId}`)
7698
await updateCopilotPayment(connection, copilotResourceId, challengeLegacyId, amount, updatedBy)
@@ -194,5 +216,6 @@ async function deleteCopilotPayment (connection, challengeLegacyId) {
194216
}
195217

196218
module.exports = {
219+
setManualCopilotPayment,
197220
setCopilotPayment
198221
}

0 commit comments

Comments
 (0)