@@ -16,20 +16,19 @@ const config = require('config')
16
16
*/
17
17
async function processUpdate ( message ) {
18
18
const createUserId = await helper . getUserId ( message . payload . createdBy )
19
- if ( ! message . payload . legacyId ) {
20
- logger . warn ( `The message ${ message . payload . id } does not contain a legacy id` )
21
- // the connection statement can't accept undefined, so set it to null
22
- message . payload . legacyId = null
19
+ const legacyId = _ . get ( message , ' payload.legacyId' , null )
20
+
21
+ if ( ! legacyId ) {
22
+ logger . warn ( `payload of challenge ${ message . payload . id } does not contain a legacy id` )
23
23
}
24
- const challengeId = _ . get ( message , 'payload.legacyId' )
25
24
const grossAmount = _ . sumBy ( _ . flatMap ( message . payload . prizeSets , 'prizes' ) , 'value' )
26
25
27
26
// the same properties of userPayment and copilotPayment
28
27
const basePayment = {
29
28
statusId : config . PAYMENT_STATUS_ID ,
30
29
modificationRationaleId : config . MODIFICATION_RATIONALE_ID ,
31
30
methodId : config . PAYMENT_METHOD_ID ,
32
- projectId : message . payload . legacyId ,
31
+ projectId : legacyId ,
33
32
charityInd : config . CHARITY_IND ,
34
33
installmentNumber : config . INSTALLMENT_NUMBER ,
35
34
createUser : createUserId ,
@@ -42,7 +41,7 @@ async function processUpdate (message) {
42
41
if ( _ . isEmpty ( winnerPrizes ) ) {
43
42
logger . warn ( `For challenge ${ challengeId } , no winner payment avaiable` )
44
43
} else if ( winnerPrizes . length !== winnerMembers . length ) {
45
- logger . error ( `For challenge ${ challengeId } , there is ${ winnerPrizes . length } user prizes but ${ winnerMembers . length } winners` )
44
+ logger . error ( `For challenge ${ legacyId } , there is ${ winnerPrizes . length } user prizes but ${ winnerMembers . length } winners` )
46
45
} else {
47
46
try {
48
47
for ( let i = 1 ; i <= winnerPrizes . length ; i ++ ) {
@@ -54,7 +53,7 @@ async function processUpdate (message) {
54
53
} , basePayment ) )
55
54
}
56
55
} catch ( error ) {
57
- logger . error ( `For challenge ${ challengeId } , add winner payments error: ${ error } ` )
56
+ logger . error ( `For challenge ${ legacyId } , add winner payments error: ${ error } ` )
58
57
}
59
58
}
60
59
0 commit comments