@@ -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
196218module . exports = {
219+ setManualCopilotPayment,
197220 setCopilotPayment
198221}
0 commit comments