@@ -50,27 +50,49 @@ async function prepare (connection, sql) {
50
50
}
51
51
52
52
/**
53
- * Set the copilot payment
53
+ * Set manual copilot payment
54
54
* @param {Number } challengeLegacyId the legacy challenge ID
55
- * @param {Number } amount the $ amount of the copilot payment
56
55
* @param {String } createdBy the create user handle
57
56
* @param {String } updatedBy the update user handle
58
57
*/
59
- async function setCopilotPayment ( challengeLegacyId , amount , createdBy , updatedBy ) {
58
+ async function setManualCopilotPayment ( challengeLegacyId , createdBy , updatedBy ) {
60
59
const connection = await helper . getInformixConnection ( )
61
60
try {
62
61
await connection . beginTransactionAsync ( )
63
62
const copilotResourceId = await getCopilotResourceId ( connection , challengeLegacyId )
64
- const copilotPayment = await getCopilotPayment ( connection , challengeLegacyId )
65
- if ( amount != null && amount >= 0 ) {
63
+ if ( copilotResourceId ) {
66
64
// 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
68
65
const paymentType = await getCopilotPaymentType ( connection , copilotResourceId )
69
66
if ( ! paymentType ) {
70
67
await createCopilotPaymentType ( connection , copilotResourceId , 'true' , updatedBy || createdBy )
71
68
} else if ( _ . toLower ( _ . toString ( paymentType . value ) ) !== 'true' ) {
72
69
await updateCopilotPaymentType ( connection , copilotResourceId , 'true' , updatedBy || createdBy )
73
70
}
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 ) {
74
96
if ( copilotPayment ) {
75
97
logger . debug ( `Copilot payment exists, updating: ${ challengeLegacyId } ` )
76
98
await updateCopilotPayment ( connection , copilotResourceId , challengeLegacyId , amount , updatedBy )
@@ -194,5 +216,6 @@ async function deleteCopilotPayment (connection, challengeLegacyId) {
194
216
}
195
217
196
218
module . exports = {
219
+ setManualCopilotPayment,
197
220
setCopilotPayment
198
221
}
0 commit comments