Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Changes according to issue #7 #8

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/services/paymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions src/services/processorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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`)
Expand All @@ -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))
}
Expand All @@ -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) {
Expand All @@ -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)
Expand Down