diff --git a/config/default.js b/config/default.js index d0767c1..e132e3e 100644 --- a/config/default.js +++ b/config/default.js @@ -42,8 +42,8 @@ module.exports = { PAYMENT_STATUS_ID: process.env.PAYMENT_STATUS_ID || 70, MODIFICATION_RATIONALE_ID: process.env.MODIFICATION_RATIONALE_ID || 1, - WINNER_PAYMENT_TYPE_ID: process.env.WINNER_PAYMENT_TYPE_ID || 65, - COPILOT_PAYMENT_TYPE_ID: process.env.COPILOT_PAYMENT_TYPE_ID || 45, + WINNER_PAYMENT_TYPE_ID: process.env.WINNER_PAYMENT_TYPE_ID || 72, + COPILOT_PAYMENT_TYPE_ID: process.env.COPILOT_PAYMENT_TYPE_ID || 74, PAYMENT_METHOD_ID: process.env.PAYMENT_METHOD_ID || 1, CHARITY_IND: process.env.CHARITY_IND || 0, diff --git a/src/services/paymentService.js b/src/services/paymentService.js index 9454bd6..05f091e 100644 --- a/src/services/paymentService.js +++ b/src/services/paymentService.js @@ -12,7 +12,7 @@ const paymentDetailIdGen = new IDGenerator('PAYMENT_DETAIL_SEQ') const paymentIdGen = new IDGenerator('PAYMENT_SEQ') // the insert statement of payment detail -const INSERT_PAYMENT_DETAIL = 'INSERT INTO payment_detail (payment_detail_id, net_amount, gross_amount, payment_status_id, modification_rationale_id, payment_desc, payment_type_id, date_modified, date_due, payment_method_id, component_project_id, create_date, charity_ind, total_amount, installment_number, create_user) VALUES(?,?,?,?,?,?,?, CURRENT, CURRENT + INTERVAL (15) DAY(5) TO DAY,?,?, CURRENT,?,?,?,?)' +const INSERT_PAYMENT_DETAIL = 'INSERT INTO payment_detail (payment_detail_id, net_amount, gross_amount, payment_status_id, modification_rationale_id, payment_desc, payment_type_id, date_modified, date_due, payment_method_id, component_project_id, create_date, charity_ind, total_amount, installment_number, create_user, jira_issue_id) VALUES(?,?,?,?,?,?,?, CURRENT, CURRENT + INTERVAL (15) DAY(5) TO DAY,?,?, CURRENT,?,?,?,?,?)' // the insert statement of payment const INSERT_PAYMENT = 'INSERT INTO payment (payment_id, user_id, most_recent_detail_id, create_date, modify_date, has_global_ad) VALUES(?,?,?, CURRENT, CURRENT, "f")' // the insert statement of payment detail xref @@ -41,7 +41,7 @@ async function createPayment (payment) { try { await connection.beginTransactionAsync() const insertDetail = await prepare(connection, INSERT_PAYMENT_DETAIL) - await insertDetail.executeAsync([paymentDetailId, payment.amount, payment.amount, payment.statusId, payment.modificationRationaleId, payment.desc, payment.typeId, payment.methodId, payment.projectId, payment.charityInd, payment.grossAmount, payment.installmentNumber, payment.createUser]) + await insertDetail.executeAsync([paymentDetailId, payment.amount, payment.amount, payment.statusId, payment.modificationRationaleId, payment.desc, payment.typeId, payment.methodId, payment.projectId, payment.charityInd, payment.grossAmount, payment.installmentNumber, payment.createUser, payment.v5ChallengeId]) const insertPayment = await prepare(connection, INSERT_PAYMENT) await insertPayment.executeAsync([paymentId, payment.memberId, paymentDetailId]) const insertDetailXref = await prepare(connection, INSERT_PAYMENT_DETAIL_XREF) diff --git a/src/services/processorService.js b/src/services/processorService.js index ee96b7e..973477d 100644 --- a/src/services/processorService.js +++ b/src/services/processorService.js @@ -17,9 +17,10 @@ const config = require('config') async function processUpdate(message) { const createUserId = await helper.getUserId(message.payload.createdBy) const legacyId = _.get(message, 'payload.legacyId', null) + const v5ChallengeId = _.get(message, 'payload.id', null) if (!legacyId) { - logger.warn(`payload of challenge ${message.payload.id} does not contain a legacy id`) + logger.warn(`payload of challenge ${v5ChallengeId} does not contain a legacy id`) } const grossAmount = _.sumBy(_.flatMap(message.payload.prizeSets, 'prizes'), 'value') @@ -32,12 +33,14 @@ async function processUpdate(message) { charityInd: config.CHARITY_IND, installmentNumber: config.INSTALLMENT_NUMBER, createUser: createUserId, - grossAmount + grossAmount, + v5ChallengeId } // add winner payment try { const winnerPrizes = _.get(_.find(message.payload.prizeSets, ['type', 'placement']), 'prizes', []) + const winnerPaymentDesc = _.get(_.find(message.payload.prizeSets, ['type', 'placement']), 'description', '') const winnerMembers = _.sortBy(_.get(message.payload, 'winners', []), ['placement']) if (_.isEmpty(winnerPrizes)) { logger.warn(`For challenge ${legacyId}, no winner payment avaiable`) @@ -49,7 +52,7 @@ async function processUpdate(message) { await paymentService.createPayment(_.assign({ memberId: winnerMembers[i - 1].userId, amount: winnerPrizes[i - 1].value, - desc: `Task - ${message.payload.name} - ${i} Place`, + desc: (winnerPaymentDesc ? winnerPaymentDesc : `Task - ${message.payload.name} - ${i} Place`), typeId: config.WINNER_PAYMENT_TYPE_ID }, basePayment)) } @@ -61,6 +64,8 @@ async function processUpdate(message) { // add copilot payment const copilotId = await helper.getCopilotId(message.payload.id) const copilotAmount = _.get(_.head(_.get(_.find(message.payload.prizeSets, ['type', 'copilot']), 'prizes', [])), 'value') + const copilotPaymentDesc = _.get(_.find(message.payload.prizeSets, ['type', 'copilot']), 'description', '') + if (!copilotAmount) { logger.warn(`For challenge ${legacyId}, no copilot payment avaiable`) } else if (!copilotId) { @@ -70,7 +75,7 @@ async function processUpdate(message) { const copilotPayment = _.assign({ memberId: copilotId, amount: copilotAmount, - desc: `Task - ${message.payload.name} - Copilot`, + desc: (copilotPaymentDesc ? copilotPaymentDesc : `Task - ${message.payload.name} - Copilot`), typeId: config.COPILOT_PAYMENT_TYPE_ID }, basePayment) await paymentService.createPayment(copilotPayment)