From f675f1561a6ef8c231858972b5a45d1ca565a005 Mon Sep 17 00:00:00 2001 From: asif Date: Mon, 8 Sep 2025 20:04:55 +0530 Subject: [PATCH] feat: added transactions record keeping feature --- src/controllers/imps.controller.js | 17 ++++++++- src/controllers/neft.controller.js | 19 +++++++++- src/controllers/rtgs.controller.js | 19 +++++++++- src/controllers/transfer.controller.js | 13 ++++++- src/routes/imps.route.js | 1 + src/routes/neft.route.js | 1 + src/routes/rtgs.route.js | 1 + src/routes/transfer.route.js | 3 +- src/services/recordkeeping.service.js | 52 ++++++++++++++++++++++++++ 9 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 src/services/recordkeeping.service.js diff --git a/src/controllers/imps.controller.js b/src/controllers/imps.controller.js index 0eb933d..7833ad2 100644 --- a/src/controllers/imps.controller.js +++ b/src/controllers/imps.controller.js @@ -1,7 +1,11 @@ const axios = require('axios'); const { logger } = require('../util/logger'); +const { + recordInterBankTransaction, +} = require('../services/recordkeeping.service'); async function send( + customerNo, fromAccount, toAccount, amount, @@ -20,7 +24,6 @@ async function send( stTransferAmount: amount, stRemarks: remarks, }; - logger.info(reqData, 'request data to be sent to IMPS server'); const response = await axios.post( 'http://localhost:6768/kccb/api/IMPS/Producer', reqData, @@ -30,7 +33,17 @@ async function send( }, } ); - logger.info(response, 'response from IMPS'); + await recordInterBankTransaction( + customerNo, + 'imps', + fromAccount, + toAccount, + ifscCode, + amount, + '', + '', + response.data + ); return response.data; } catch (error) { logger.error(error, 'error from IMPS'); diff --git a/src/controllers/neft.controller.js b/src/controllers/neft.controller.js index 091b7a3..a43acd8 100644 --- a/src/controllers/neft.controller.js +++ b/src/controllers/neft.controller.js @@ -1,6 +1,10 @@ const axios = require('axios'); +const { + recordInterBankTransaction, +} = require('../services/recordkeeping.service'); async function send( + customerNo, fromAccount, toAccount, amount, @@ -8,6 +12,7 @@ async function send( beneficiaryName, remitterName ) { + const commission = 0; try { const response = await axios.post( 'http://localhost:8690/kccb/Neftfundtransfer', @@ -15,7 +20,7 @@ async function send( stFromAcc: fromAccount, stToAcc: toAccount, stTranAmt: amount, - stCommission: 0, + stCommission: commission, stIfscCode: ifscCode, stFullName: remitterName, stBeneName: beneficiaryName, @@ -24,6 +29,18 @@ async function send( stAddress3: '', } ); + await recordInterBankTransaction( + customerNo, + 'neft', + fromAccount, + toAccount, + ifscCode, + amount, + commission, + beneficiaryName, + remitterName, + response.data.status + ); return response.data; } catch (error) { throw new Error( diff --git a/src/controllers/rtgs.controller.js b/src/controllers/rtgs.controller.js index e5c9625..352cf21 100644 --- a/src/controllers/rtgs.controller.js +++ b/src/controllers/rtgs.controller.js @@ -1,6 +1,10 @@ const axios = require('axios'); +const { + recordInterBankTransaction, +} = require('../services/recordkeeping.service'); async function send( + customerNo, fromAccount, toAccount, amount, @@ -8,6 +12,7 @@ async function send( beneficiaryName, remitterName ) { + const commission = 0; try { const response = await axios.post( 'http://localhost:8690/kccb/Rtgsfundtransfer', @@ -15,7 +20,7 @@ async function send( stFromAcc: fromAccount, stToAcc: toAccount, stTranAmt: amount, - stCommission: 0, + stCommission: commission, stIfscCode: ifscCode, stFullName: remitterName, stBeneName: beneficiaryName, @@ -24,6 +29,18 @@ async function send( stAddress3: '', } ); + await recordInterBankTransaction( + customerNo, + 'rtgs', + fromAccount, + toAccount, + ifscCode, + amount, + commission, + beneficiaryName, + remitterName, + response.data.status + ); return response.data; } catch (error) { throw new Error( diff --git a/src/controllers/transfer.controller.js b/src/controllers/transfer.controller.js index d0688e3..028c49d 100644 --- a/src/controllers/transfer.controller.js +++ b/src/controllers/transfer.controller.js @@ -1,11 +1,14 @@ const axios = require('axios'); +const { + recordIntraBankTransaction, +} = require('../services/recordkeeping.service'); async function transfer( fromAccountNo, toAccountNo, toAccountType, amount, - // narration = 'transfer from mobile' + customerNo, narration = '' ) { try { @@ -19,6 +22,14 @@ async function transfer( narration, } ); + await recordIntraBankTransaction( + customerNo, + fromAccountNo, + toAccountNo, + toAccountType, + amount, + response.data.status + ); return response.data; } catch (error) { throw new Error( diff --git a/src/routes/imps.route.js b/src/routes/imps.route.js index d0ff998..5294270 100644 --- a/src/routes/imps.route.js +++ b/src/routes/imps.route.js @@ -13,6 +13,7 @@ const impsRoute = async (req, res) => { try { const result = await impsController.send( + req.user, fromAccount, toAccount, amount, diff --git a/src/routes/neft.route.js b/src/routes/neft.route.js index 89342b3..ae5d78b 100644 --- a/src/routes/neft.route.js +++ b/src/routes/neft.route.js @@ -19,6 +19,7 @@ const neftRoute = async (req, res) => { try { const result = await neftController.send( + req.user, fromAccount, toAccount, amount, diff --git a/src/routes/rtgs.route.js b/src/routes/rtgs.route.js index c0832c5..14ed607 100644 --- a/src/routes/rtgs.route.js +++ b/src/routes/rtgs.route.js @@ -19,6 +19,7 @@ const rtgsRoute = async (req, res) => { try { const result = await rtgsController.send( + req.user, fromAccount, toAccount, amount, diff --git a/src/routes/transfer.route.js b/src/routes/transfer.route.js index 3fd9afa..349dd3e 100644 --- a/src/routes/transfer.route.js +++ b/src/routes/transfer.route.js @@ -14,7 +14,8 @@ const transferRoute = async (req, res) => { fromAccount, toAccount, toAccountType, - amount + amount, + req.user ); if (result.status === 'O.K.') { diff --git a/src/services/recordkeeping.service.js b/src/services/recordkeeping.service.js new file mode 100644 index 0000000..43fa20a --- /dev/null +++ b/src/services/recordkeeping.service.js @@ -0,0 +1,52 @@ +const db = require('../config/db'); + +const recordIntraBankTransaction = async ( + customerNo, + fromAccount, + toAccount, + accountType, + amount, + status +) => { + const trxType = 'TRF'; + const query = + 'INSERT INTO transactions (customer_no, trx_type, from_account, to_account, to_account_type, amount, status) VALUES ($1, $2, $3, $4, $5, $6, $7)'; + await db.query(query, [ + customerNo, + trxType, + fromAccount, + toAccount, + accountType, + amount, + status, + ]); +}; +const recordInterBankTransaction = async ( + customerNo, + trxType, + fromAccount, + toAccount, + ifscCode, + amount, + commission, + beneficiaryName, + remitterName, + status +) => { + const query = + 'INSERT INTO transactions (customer_no, trx_type, from_account, to_account, ifsc_code, amount, commission, beneficiary_name, remitter_name, status) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)'; + await db.query(query, [ + customerNo, + trxType, + fromAccount, + toAccount, + ifscCode, + amount, + commission, + beneficiaryName, + remitterName, + status, + ]); +}; + +module.exports = { recordIntraBankTransaction, recordInterBankTransaction };