added two methods to get registered beneficiaries for a customer

This commit is contained in:
2025-08-08 20:40:10 +05:30
parent e75ff4d658
commit 123d5c9f1d

View File

@@ -1,6 +1,7 @@
const axios = require('axios'); const axios = require('axios');
const { logger } = require('../util/logger'); const { logger } = require('../util/logger');
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
const db = require('../config/db');
async function validateWithinBank(accountNo) { async function validateWithinBank(accountNo) {
const url = 'http://localhost:8687/kccb/cbs/acctInfo/details'; const url = 'http://localhost:8687/kccb/cbs/acctInfo/details';
@@ -36,4 +37,33 @@ async function validateOutsideBank(accountNo, ifscCode, name) {
} }
} }
module.exports = { validateWithinBank, validateOutsideBank }; async function getSingleBeneficiary(customerNo, accountNo) {
const queryStr =
'SELECT b.account_no, b.name, b.account_type, b.ifsc_code, i.bank_name, i.branch_name FROM beneficiaries b JOIN ifsc_details i ON b.ifsc_code = i.ifsc_code WHERE customer_no = $1 AND account_no = $2';
const result = await db.query(queryStr, [customerNo, accountNo]);
return result.rows[0];
}
async function getAllBeneficiaries(customerNo) {
const queryStr =
'SELECT b.account_no, b.name, b.account_type, b.ifsc_code, i.bank_name, i.branch_name FROM beneficiaries b JOIN ifsc_details i ON b.ifsc_code = i.ifsc_code WHERE customer_no = $1';
const result = await db.query(queryStr, [customerNo]);
const list = result.rows.map((row) => {
return {
accountNo: row['account_no'],
name: row['name'],
accountType: row['account_type'],
ifscCdoe: row['ifsc_code'],
bankName: row['bank_name'],
branchName: row['branch_name'],
}
});
return list;
}
module.exports = {
validateWithinBank,
validateOutsideBank,
getAllBeneficiaries,
getSingleBeneficiary,
};