@@ -181,12 +181,12 @@ async function getExistingChallengeIdIfExists(dbPayment) {
181181 project : dbPayment . project ,
182182 username : dbPayment . username ,
183183 closed : 'false' ,
184- challengeId : { gt : 0 } ,
185184 } ) ;
186185
187186 // if no existing challenge found then it will be created by processor
188187 if ( existingPayments ) {
189188 dbPayment . challengeId = existingPayments . challengeId ;
189+ dbPayment . challengeUUID = existingPayments . challengeUUID ;
190190 }
191191 return dbPayment ;
192192}
@@ -212,7 +212,7 @@ async function create(topcoderUser, payment) {
212212 let dbPayment = await dbHelper . create ( CopilotPayment , payment ) ;
213213
214214 dbPayment = await getExistingChallengeIdIfExists ( dbPayment ) ;
215- if ( ! _ . isNumber ( dbPayment . challengeId ) && payment . amount <= 1 ) {
215+ if ( ! _ . isString ( dbPayment . challengeUUID ) && payment . amount <= 1 ) {
216216 throw new Error ( 'The amount must be greater than 1' ) ;
217217 }
218218 await dbHelper . update ( CopilotPayment , dbPayment . id , dbPayment ) ;
@@ -242,29 +242,33 @@ async function update(topcoderUser, payment) {
242242
243243 // if nothing is changed then discard
244244 if ( dbPayment . project === payment . project && dbPayment . amount === payment . amount && dbPayment . description === payment . description ) { // eslint-disable-line
245- return dbPayment . toJSON ( ) ;
245+ return dbPayment ;
246246 }
247247
248248 const existingProjectId = dbPayment . project ;
249249 const existingChallengeId = dbPayment . challengeId ;
250+ const existingChallengeUUID = dbPayment . challengeUUID ;
250251
251252 if ( existingProjectId !== payment . project ) {
252253 dbPayment . challengeId = null ;
253254 payment . challengeId = null ;
255+
256+ dbPayment . challengeUUID = null ;
257+ payment . challengeUUID = null ;
254258 }
255259
256260 dbPayment . amount = payment . amount ;
257261 dbPayment . description = payment . description ;
258262 dbPayment . project = payment . project ;
259263
260264 dbPayment = await getExistingChallengeIdIfExists ( dbPayment ) ;
261- if ( ! _ . isNumber ( dbPayment . challengeId ) && payment . amount <= 1 ) {
265+ if ( ! _ . isNull ( dbPayment . challengeUUID ) && payment . amount <= 1 ) {
262266 throw new Error ( 'The amount must be greater than 1' ) ;
263267 }
264268
265269 await dbHelper . update ( CopilotPayment , dbPayment . id , dbPayment ) ;
266270 const paymentUpdateEvent = {
267- event : dbPayment . challengeId > 0 ? 'copilotPayment.update' : 'copilotPayment.add' ,
271+ event : dbPayment . challengeUUID ? 'copilotPayment.update' : 'copilotPayment.add' ,
268272 data : {
269273 payment : _ . assign ( { } , dbPayment ) ,
270274 copilot : topcoderUser ,
@@ -281,6 +285,7 @@ async function update(topcoderUser, payment) {
281285 payment : {
282286 project : existingProjectId ,
283287 challengeId : existingChallengeId ,
288+ challengeUUID : existingChallengeUUID
284289 } ,
285290 copilot : topcoderUser ,
286291 } ,
0 commit comments