@@ -64,7 +64,7 @@ async function getExistingChallengeIdIfExists(event, dbPayment) {
64
64
// check if there is existing active challenge associated with this project
65
65
const existingPayments = await CopilotPayment . findOne ( {
66
66
project : dbPayment . project ,
67
- username : event . data . copilot . handle ,
67
+ username : event . project . copilot ,
68
68
closed : false ,
69
69
challengeId : {
70
70
$gt : 0
@@ -135,7 +135,7 @@ async function _checkAndReSchedule(event, payment) {
135
135
// get all unclosed payments for given project and user
136
136
const existingPending = await CopilotPayment . find ( {
137
137
project : payment . project ,
138
- username : event . data . copilot . handle ,
138
+ username : event . project . copilot ,
139
139
closed : false ,
140
140
status : 'challenge_creation_pending'
141
141
} ) ;
@@ -158,7 +158,7 @@ async function _checkAndReSchedule(event, payment) {
158
158
* @private
159
159
*/
160
160
async function handlePaymentAdd ( event , payment ) {
161
- const copilot = event . data . copilot ;
161
+ const copilot = { handle : event . project . copilot } ;
162
162
163
163
payment = await getExistingChallengeIdIfExists ( event , payment ) ;
164
164
if ( ! _ . isNil ( payment . challengeId ) ) {
@@ -232,7 +232,7 @@ async function handlePaymentAdd(event, payment) {
232
232
* @private
233
233
*/
234
234
async function handlePaymentUpdate ( event , payment ) {
235
- const copilot = event . data . copilot ;
235
+ const copilot = { handle : event . project . copilot } ;
236
236
await _updateChallenge ( copilot . handle , payment . project , payment . challengeId ) ;
237
237
logger . debug ( `updated payment for challenge ${ payment . challengeId } successful.` ) ;
238
238
}
@@ -245,7 +245,7 @@ async function handlePaymentUpdate(event, payment) {
245
245
* @private
246
246
*/
247
247
async function handlePaymentDelete ( event , payment ) {
248
- const copilot = event . data . copilot ;
248
+ const copilot = { handle : event . project . copilot } ;
249
249
await _updateChallenge ( copilot . handle , payment . project , payment . challengeId ) ;
250
250
logger . debug ( `updated payment for challenge ${ payment . challengeId } successful.` ) ;
251
251
}
@@ -255,11 +255,16 @@ async function handlePaymentDelete(event, payment) {
255
255
* @param {Object } event the event
256
256
*/
257
257
async function handlePaymentUpdates ( event ) {
258
- const copilot = event . data . copilot ;
258
+ const projectIds = await Project . find ( {
259
+ $or : [
260
+ { owner : event . copilot . handle } ,
261
+ { copilot : event . copilot . handle }
262
+ ]
263
+ } ) . select ( '_id' ) ;
259
264
260
265
// get all unclosed payments for current user
261
266
const dbPayments = await CopilotPayment . find ( {
262
- username : copilot . handle ,
267
+ project : { $in : projectIds } ,
263
268
closed : false
264
269
} ) ;
265
270
if ( dbPayments ) {
@@ -269,7 +274,7 @@ async function handlePaymentUpdates(event) {
269
274
const challengeId = challengeIds [ i ] ;
270
275
const challengeDetail = await topcoderApiHelper . getChallengeById ( challengeId ) ;
271
276
if ( challengeDetail && challengeDetail . currentStatus === 'Completed' ) {
272
- await CopilotPayment . updateMany ( { challengeId, username : copilot . handle , closed : false } , { closed : true } ) ;
277
+ await CopilotPayment . updateMany ( { challengeId, closed : false } , { closed : true } ) ;
273
278
}
274
279
}
275
280
logger . debug ( 'Success updating payments status.' ) ;
@@ -293,6 +298,9 @@ async function process(event) {
293
298
if ( _ . isNil ( payment . challengeId ) ) {
294
299
delete payment . challengeId ;
295
300
}
301
+ if ( payment . project ) {
302
+ event . project = await Project . findById ( payment . project ) ;
303
+ }
296
304
if ( event . event === 'copilotPayment.add' ) {
297
305
await handlePaymentAdd ( event , payment ) ;
298
306
} else if ( event . event === 'copilotPayment.update' ) {
0 commit comments