@@ -181,12 +181,12 @@ async function getExistingChallengeIdIfExists(dbPayment) {
181
181
project : dbPayment . project ,
182
182
username : dbPayment . username ,
183
183
closed : 'false' ,
184
- challengeId : { gt : 0 } ,
185
184
} ) ;
186
185
187
186
// if no existing challenge found then it will be created by processor
188
187
if ( existingPayments ) {
189
188
dbPayment . challengeId = existingPayments . challengeId ;
189
+ dbPayment . challengeUUID = existingPayments . challengeUUID ;
190
190
}
191
191
return dbPayment ;
192
192
}
@@ -212,7 +212,7 @@ async function create(topcoderUser, payment) {
212
212
let dbPayment = await dbHelper . create ( CopilotPayment , payment ) ;
213
213
214
214
dbPayment = await getExistingChallengeIdIfExists ( dbPayment ) ;
215
- if ( ! _ . isNumber ( dbPayment . challengeId ) && payment . amount <= 1 ) {
215
+ if ( ! _ . isString ( dbPayment . challengeUUID ) && payment . amount <= 1 ) {
216
216
throw new Error ( 'The amount must be greater than 1' ) ;
217
217
}
218
218
await dbHelper . update ( CopilotPayment , dbPayment . id , dbPayment ) ;
@@ -242,29 +242,33 @@ async function update(topcoderUser, payment) {
242
242
243
243
// if nothing is changed then discard
244
244
if ( dbPayment . project === payment . project && dbPayment . amount === payment . amount && dbPayment . description === payment . description ) { // eslint-disable-line
245
- return dbPayment . toJSON ( ) ;
245
+ return dbPayment ;
246
246
}
247
247
248
248
const existingProjectId = dbPayment . project ;
249
249
const existingChallengeId = dbPayment . challengeId ;
250
+ const existingChallengeUUID = dbPayment . challengeUUID ;
250
251
251
252
if ( existingProjectId !== payment . project ) {
252
253
dbPayment . challengeId = null ;
253
254
payment . challengeId = null ;
255
+
256
+ dbPayment . challengeUUID = null ;
257
+ payment . challengeUUID = null ;
254
258
}
255
259
256
260
dbPayment . amount = payment . amount ;
257
261
dbPayment . description = payment . description ;
258
262
dbPayment . project = payment . project ;
259
263
260
264
dbPayment = await getExistingChallengeIdIfExists ( dbPayment ) ;
261
- if ( ! _ . isNumber ( dbPayment . challengeId ) && payment . amount <= 1 ) {
265
+ if ( ! _ . isNull ( dbPayment . challengeUUID ) && payment . amount <= 1 ) {
262
266
throw new Error ( 'The amount must be greater than 1' ) ;
263
267
}
264
268
265
269
await dbHelper . update ( CopilotPayment , dbPayment . id , dbPayment ) ;
266
270
const paymentUpdateEvent = {
267
- event : dbPayment . challengeId > 0 ? 'copilotPayment.update' : 'copilotPayment.add' ,
271
+ event : dbPayment . challengeUUID ? 'copilotPayment.update' : 'copilotPayment.add' ,
268
272
data : {
269
273
payment : _ . assign ( { } , dbPayment ) ,
270
274
copilot : topcoderUser ,
@@ -281,6 +285,7 @@ async function update(topcoderUser, payment) {
281
285
payment : {
282
286
project : existingProjectId ,
283
287
challengeId : existingChallengeId ,
288
+ challengeUUID : existingChallengeUUID
284
289
} ,
285
290
copilot : topcoderUser ,
286
291
} ,
0 commit comments