Compare commits
26 Commits
E_mandate
...
fetch-from
| Author | SHA1 | Date | |
|---|---|---|---|
| 785db2c8a4 | |||
| b1cf06ef08 | |||
| 7e852763ff | |||
| c5b5927398 | |||
| c8adc3688a | |||
| 69c5ccba1d | |||
| c3875afbd2 | |||
| 9446abd88b | |||
| 7cf19000d1 | |||
| 61b85abdd1 | |||
| 1e831acfe2 | |||
| c481e4f139 | |||
| 12750e833c | |||
| bf06706b29 | |||
| 7e162e741d | |||
| a04830cdb2 | |||
| 12f0881c9b | |||
| b0c9cb8038 | |||
| a8a576f5c1 | |||
| 4c63ccf3ae | |||
| 3262ff53bf | |||
| 60cb0076f1 | |||
| b68c8a08c2 | |||
| 1ebe666bb3 | |||
| 689b00aec7 | |||
| 56c69e54de |
@@ -62,6 +62,7 @@ async function getUserDetails(req, res) {
|
||||
res.status(500).json({ error: 'invalid CIF number' });
|
||||
}
|
||||
}
|
||||
|
||||
async function getUserRights(req, res) {
|
||||
const { CIF } = req.query;
|
||||
if (!CIF) {
|
||||
@@ -71,13 +72,13 @@ async function getUserRights(req, res) {
|
||||
}
|
||||
const userDetails = await adminAuthService.getCustomerDetailsFromDB(CIF);
|
||||
if (!userDetails)
|
||||
return res.status(401).json({ error: 'invalid CIF number or No rights is present for the user.' });
|
||||
return res.status(404).json({ error: 'invalid CIF number or No rights is present for the user.' });
|
||||
return res.json(userDetails);
|
||||
}
|
||||
|
||||
async function UserRights(req, res) {
|
||||
try {
|
||||
const { CIF, ib_access_level, mb_access_level } = req.body;
|
||||
const { CIF, ib_access_level, mb_access_level, ib_limit, mb_limit } = req.body;
|
||||
|
||||
if (!CIF) {
|
||||
return res.status(400).json({ error: 'CIF number is required' });
|
||||
@@ -93,23 +94,26 @@ async function UserRights(req, res) {
|
||||
if (FirstTimeLogin && dayjs(currentTime).diff(dayjs(user.created_at), 'day') > 8) {
|
||||
// Password expired, resend
|
||||
await db.query(
|
||||
'UPDATE users SET password_hash=$2, updated_at=$5, ib_access_level=$3, mb_access_level=$4 WHERE customer_no=$1',
|
||||
[CIF, password, ib_access_level, mb_access_level, currentTime]
|
||||
'UPDATE users SET password_hash=$2, updated_at=$5, ib_access_level=$3, mb_access_level=$4 ,inb_limit_amount=$6,mobile_limit_amount=$7 WHERE customer_no=$1',
|
||||
[CIF, password, ib_access_level, mb_access_level, currentTime, ib_limit, mb_limit]
|
||||
);
|
||||
logger.info("Admin sended the OTP");
|
||||
return res.json({ otp: first_time_pass });
|
||||
}
|
||||
// Just update access levels and timestamp
|
||||
await db.query(
|
||||
'UPDATE users SET updated_at=$4, ib_access_level=$2, mb_access_level=$3 WHERE customer_no=$1',
|
||||
[CIF, ib_access_level, mb_access_level, currentTime]
|
||||
'UPDATE users SET updated_at=$4, ib_access_level=$2, mb_access_level=$3 ,inb_limit_amount=$5,mobile_limit_amount=$6 WHERE customer_no=$1',
|
||||
[CIF, ib_access_level, mb_access_level, currentTime, ib_limit, mb_limit]
|
||||
);
|
||||
logger.info("Admin Updated the user.");
|
||||
return res.json({ message: "User updated successfully." });
|
||||
} else {
|
||||
// User does not exist, insert
|
||||
await db.query(
|
||||
'INSERT INTO users (customer_no, password_hash, ib_access_level, mb_access_level) VALUES ($1, $2, $3, $4)',
|
||||
[CIF, password, ib_access_level, mb_access_level]
|
||||
'INSERT INTO users (customer_no, password_hash, ib_access_level, mb_access_level ,inb_limit_amount,mobile_limit_amount) VALUES ($1, $2, $3, $4 ,$5 ,$6)',
|
||||
[CIF, password, ib_access_level, mb_access_level, ib_limit, mb_limit]
|
||||
);
|
||||
logger.info("New user enroll by admin.");
|
||||
return res.json({ otp: first_time_pass });
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -119,4 +123,30 @@ async function UserRights(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { login, fetchAdminDetails, getUserDetails, UserRights, getUserRights };
|
||||
async function handleUnlockUser(req, res) {
|
||||
try {
|
||||
const { user, action } = req.body;
|
||||
const adminUserName = req.admin;
|
||||
if (!user) {
|
||||
return res.status(400).json({ error: "CIF or username is required" });
|
||||
}
|
||||
const userDetails = await adminAuthService.getCustomerDetailsFromDB(user);
|
||||
if (!userDetails) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ error: "Invalid CIF number or username" });
|
||||
}
|
||||
await adminAuthService.updateUserLockStatus(user, action,adminUserName);
|
||||
const statusText = action ? "locked" : "unlocked";
|
||||
logger.info(`User ${user} has been successfully ${statusText}.`);
|
||||
|
||||
return res.json({
|
||||
message: `User ${user} has been successfully ${statusText}.`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Unlock user error:", error);
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { login, fetchAdminDetails, getUserDetails, UserRights, getUserRights, handleUnlockUser };
|
||||
|
||||
@@ -168,6 +168,23 @@ async function tpin(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
async function transPassword(req, res) {
|
||||
const customerNo = req.user;
|
||||
try {
|
||||
const user = await authService.findUserByCustomerNo(customerNo);
|
||||
if (!user) return res.status(404).json({ message: 'USER_NOT_FOUND' });
|
||||
if (!user.transaction_password) {
|
||||
return res.json({ transPasswordSet: false });
|
||||
} else {
|
||||
return res.json({ transPasswordSet: true });
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err, 'error occured while checking transaction password');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function setTpin(req, res) {
|
||||
const customerNo = req.user;
|
||||
try {
|
||||
@@ -221,12 +238,30 @@ async function setLoginPassword(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
async function setTransactionPassword(req, res) {
|
||||
async function setTransPassword(req, res) {
|
||||
const customerNo = req.user;
|
||||
try {
|
||||
const user = await authService.findUserByCustomerNo(customerNo);
|
||||
if (!user) return res.status(404).json({ error: 'USER_NOT_FOUND' });
|
||||
const { transaction_password } = req.body;
|
||||
// if (user.transaction_password) {
|
||||
// const isMatchWithOldPassword = await comparePassword(
|
||||
// transaction_password,
|
||||
// user.transaction_password
|
||||
// );
|
||||
// if (isMatchWithOldPassword)
|
||||
// return res.status(500).json({
|
||||
// error: 'New transaction Password will be different from Previous Password',
|
||||
// });
|
||||
// }
|
||||
const isMatchWithLoginPassword = await comparePassword(
|
||||
transaction_password,
|
||||
user.password_hash
|
||||
);
|
||||
if (isMatchWithLoginPassword)
|
||||
return res.status(500).json({
|
||||
error: 'New transaction Password will be different from Login Password',
|
||||
});
|
||||
authService.setTransactionPassword(customerNo, transaction_password);
|
||||
return res.json({ message: 'Transaction Password set' });
|
||||
} catch (error) {
|
||||
@@ -291,6 +326,14 @@ async function changeTransPassword(req, res) {
|
||||
error:
|
||||
'New Transaction Password will be different from Previous Transaction Password',
|
||||
});
|
||||
const isMatchWithLoginPassword = await comparePassword(
|
||||
newTPsw,
|
||||
user.password_hash
|
||||
);
|
||||
if (isMatchWithLoginPassword)
|
||||
return res.status(500).json({
|
||||
error: 'New transaction Password will be different from Login Password',
|
||||
});
|
||||
authService.changeTransPassword(customerNo, newTPsw);
|
||||
return res.json({
|
||||
message: 'New Transaction Password changed successfully',
|
||||
@@ -395,7 +438,8 @@ module.exports = {
|
||||
setTpin,
|
||||
changeTpin,
|
||||
setLoginPassword,
|
||||
setTransactionPassword,
|
||||
transPassword,
|
||||
setTransPassword,
|
||||
fetchUserDetails,
|
||||
changeLoginPassword,
|
||||
changeTransPassword,
|
||||
|
||||
@@ -114,10 +114,18 @@ async function SendOtp(req, res) {
|
||||
case 'TLIMIT_SET':
|
||||
message = templates.TLIMIT_SET(amount);
|
||||
break;
|
||||
case 'LPWORD_CHANGE':
|
||||
message = templates.LPWORD_CHANGE;
|
||||
break;
|
||||
case 'TPWORD_CHANGE':
|
||||
message = templates.TPWORD_CHANGE;
|
||||
break;
|
||||
default:
|
||||
return res.status(400).json({ error: 'Invalid OTP type' });
|
||||
}
|
||||
|
||||
if (message.includes('OTP')) {
|
||||
await setJson(`otp:${mobileNumber}`, otp, 300);
|
||||
}
|
||||
// Call SMS API
|
||||
const response = await axios.post(
|
||||
'http://localhost:9999/api/SendtoMessage',
|
||||
@@ -126,12 +134,8 @@ async function SendOtp(req, res) {
|
||||
stMessage: message,
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data) {
|
||||
// Save OTP only if it's OTP based (skip notifications without OTP)
|
||||
if (message.includes('OTP')) {
|
||||
await setJson(`otp:${mobileNumber}`, otp, 300);
|
||||
}
|
||||
logger.info(`Sent OTP [${otp}] for type [${type}] to ${mobileNumber}`);
|
||||
}
|
||||
return res.status(200).json({ message: 'Message sent successfully' });
|
||||
@@ -152,15 +156,18 @@ async function VerifyOtp(req, res) {
|
||||
|
||||
try {
|
||||
const storedOtp = await getJson(`otp:${mobileNumber}`);
|
||||
logger.info("OTP is stored");
|
||||
|
||||
if (!storedOtp) {
|
||||
logger.error("OTP expired or not found");
|
||||
return res.status(400).json({ error: 'OTP expired or not found' });
|
||||
}
|
||||
|
||||
if (parseInt(otp, 10) !== parseInt(storedOtp, 10)) {
|
||||
logger.error("Invalid OTP");
|
||||
return res.status(400).json({ error: 'Invalid OTP' });
|
||||
}
|
||||
|
||||
logger.info(`OTP verified with mobile number -${mobileNumber}`);
|
||||
return res.status(200).json({ message: 'OTP verified successfully' });
|
||||
} catch (err) {
|
||||
logger.error(err, 'Error verifying OTP');
|
||||
@@ -193,6 +200,7 @@ async function sendForSetPassword(req, res) {
|
||||
}
|
||||
);
|
||||
await setJson(`otp:${mobileNumber}`, otp, 300);
|
||||
logger.info(`Sent OTP [${otp}] to ${mobileNumber}`);
|
||||
return res.status(200).json({ message: 'OTP_SENT' });
|
||||
} catch (err) {
|
||||
logger.error(err, 'Error sending OTP');
|
||||
|
||||
178
src/controllers/report.controller.js
Normal file
178
src/controllers/report.controller.js
Normal file
@@ -0,0 +1,178 @@
|
||||
|
||||
const reportService = require('../services/report.service');
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
async function active_users(req, res) {
|
||||
const { from_date, to_date } = req.body;
|
||||
if (!from_date || !to_date) {
|
||||
return res.status(400).json({ error: 'from_date and to_date are required' });
|
||||
}
|
||||
try {
|
||||
const users = await reportService.total_users(from_date, to_date);
|
||||
const activeUsers = users.filter(u => u.is_first_login === false);
|
||||
const inactiveUsers = users.filter(u => u.is_first_login === true);
|
||||
const active_user_list = activeUsers.map(u => ({
|
||||
customer_no: u.customer_no,
|
||||
user_name: u.preferred_name,
|
||||
created_at: u.created_at,
|
||||
last_login: u.last_login,
|
||||
status: "active"
|
||||
}));
|
||||
logger.info(`fetch total number of users and active users from date ${from_date} to ${to_date}`);
|
||||
res.json({
|
||||
total_users: users.length,
|
||||
active_users: activeUsers.length,
|
||||
inactive_users: inactiveUsers.length,
|
||||
active_user_list: active_user_list
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch data');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function inactive_users(req, res) {
|
||||
const { from_date, to_date } = req.body;
|
||||
if (!from_date || !to_date) {
|
||||
return res.status(400).json({ error: 'from_date and to_date are required' });
|
||||
}
|
||||
try {
|
||||
const users = await reportService.total_users(from_date, to_date);
|
||||
const activeUsers = users.filter(u => u.is_first_login === false);
|
||||
const inactiveUsers = users.filter(u => u.is_first_login === true);
|
||||
const inactive_user_list = inactiveUsers.map(u => ({
|
||||
customer_no: u.customer_no,
|
||||
user_name: u.preferred_name,
|
||||
created_at: u.created_at,
|
||||
last_login: u.last_login,
|
||||
status: "in-active"
|
||||
}));
|
||||
logger.info(`fetch total number of users and inactive users from date ${from_date} to ${to_date}`);
|
||||
res.json({
|
||||
total_users: users.length,
|
||||
active_users: activeUsers.length,
|
||||
inactive_users: inactiveUsers.length,
|
||||
inactive_user_list: inactive_user_list
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch data');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function getTransactions(req, res) {
|
||||
const {
|
||||
trx_type,
|
||||
from_date,
|
||||
to_date,
|
||||
client,
|
||||
amount_min,
|
||||
amount_max,
|
||||
customer_no
|
||||
} = req.body;
|
||||
|
||||
if (!trx_type || !from_date || !to_date) {
|
||||
return res.status(400).json({ error: 'trx_type, from_date and to_date are required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const filters = {
|
||||
trx_type,
|
||||
from_date,
|
||||
to_date,
|
||||
client,
|
||||
amount_min,
|
||||
amount_max,
|
||||
customer_no
|
||||
};
|
||||
|
||||
const transactions = await reportService.getTransactions(filters);
|
||||
const transactions_list = transactions.map(u => ({
|
||||
|
||||
customer_no: u.customer_no,
|
||||
from_account: u.from_account,
|
||||
to_account: u.to_account,
|
||||
ifsc_code: u.ifsc_code,
|
||||
amount: u.amount,
|
||||
created_at: u.created_at,
|
||||
trx_type: u.trx_type,
|
||||
status: u.status,
|
||||
}));
|
||||
|
||||
res.json({ count: transactions.length, transactions_list });
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch transactions');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function getFailedTransactions(req, res) {
|
||||
const {
|
||||
from_date,
|
||||
to_date,
|
||||
customer_no
|
||||
} = req.body;
|
||||
|
||||
if (!from_date || !to_date) {
|
||||
return res.status(400).json({ error: 'from_date and to_date are required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const filters = {
|
||||
from_date,
|
||||
to_date,
|
||||
customer_no
|
||||
};
|
||||
|
||||
const transactions = await reportService.getFailedTransactions(filters);
|
||||
const transactions_list = transactions.map(u => ({
|
||||
|
||||
customer_no: u.customer_no,
|
||||
from_account: u.from_account,
|
||||
to_account: u.to_account,
|
||||
ifsc_code: u.ifsc_code,
|
||||
amount: u.amount,
|
||||
created_at: u.created_at,
|
||||
trx_type: u.trx_type,
|
||||
status: u.status,
|
||||
}));
|
||||
|
||||
res.json({ count: transactions.length, transactions_list });
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch transactions');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function getDetailsOfNotLoginWithinDuration(req, res) {
|
||||
const {
|
||||
duration
|
||||
} = req.body;
|
||||
|
||||
if (!duration) {
|
||||
return res.status(400).json({ error: 'Duration are required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const users = await reportService.getNotLogin(duration);
|
||||
const user_list = users.map(u => ({
|
||||
|
||||
customer_no: u.customer_no,
|
||||
user_name: u.preferred_name,
|
||||
last_login: u.last_login,
|
||||
created_at: u.created_at,
|
||||
locked: u.locked,
|
||||
status: u.status,
|
||||
}));
|
||||
|
||||
res.json({ count: users.length, user_list });
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch not logged in user details');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { active_users, inactive_users, getTransactions, getFailedTransactions, getDetailsOfNotLoginWithinDuration };
|
||||
@@ -13,7 +13,6 @@ function checkAdmin (req,res,next){
|
||||
const token = authHeader.split(' ')[1];
|
||||
try {
|
||||
const payload = verifyToken(token);
|
||||
// console.log("hi",payload);
|
||||
if(payload.customerNo && payload.role === 'admin'){
|
||||
req.admin = payload.customerNo;
|
||||
next();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
function verifyClient(req, res, next) {
|
||||
console.log('printing headers');
|
||||
console.log(req.headers);
|
||||
const clientHeader = req.headers['x-login-type'];
|
||||
|
||||
if (!clientHeader || (clientHeader !== 'MB' && clientHeader !== 'IB' && clientHeader !== 'eMandate' && clientHeader !=='Admin')) {
|
||||
if (!clientHeader || (clientHeader !== 'MB' && clientHeader !== 'IB' && clientHeader !== 'NPCI' && clientHeader !== 'eMandate' && clientHeader !=='Admin')) {
|
||||
logger.error(
|
||||
`Invalid or missing client header. Expected 'MB' or 'IB'. Found ${clientHeader}`
|
||||
);
|
||||
|
||||
@@ -7,6 +7,9 @@ const router = express.Router();
|
||||
router.post('/login', adminAuthController.login);
|
||||
router.get('/admin_details', adminAuthenticate, adminAuthController.fetchAdminDetails);
|
||||
router.get('/fetch/customer_details',adminAuthenticate,adminAuthController.getUserDetails);
|
||||
|
||||
// User configuration
|
||||
router.post('/user/rights',adminAuthenticate,adminAuthController.UserRights);
|
||||
router.get('/user/rights',adminAuthenticate,adminAuthController.getUserRights);
|
||||
router.post('/user/unlock',adminAuthenticate,adminAuthController.handleUnlockUser);
|
||||
module.exports = router;
|
||||
|
||||
19
src/routes/atm.route.js
Normal file
19
src/routes/atm.route.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const express = require('express');
|
||||
const { logger } = require('../util/logger');
|
||||
const db = require('../config/db');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const atmRoute = async (req, res) => {
|
||||
try {
|
||||
const query_str = 'SELECT * FROM atm_details';
|
||||
const result = await db.query(query_str);
|
||||
return res.json(result.rows);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
res.status(500).json({ error: 'INTERNAL SERVER ERROR' });
|
||||
}
|
||||
};
|
||||
router.get('/', atmRoute);
|
||||
|
||||
module.exports = router;
|
||||
@@ -6,20 +6,24 @@ const router = express.Router();
|
||||
|
||||
router.post('/login', authController.login);
|
||||
router.get('/user_details', authenticate, authController.fetchUserDetails);
|
||||
|
||||
router.get('/tpin', authenticate, authController.tpin);
|
||||
router.post('/tpin', authenticate, authController.setTpin);
|
||||
router.post('/change/tpin', authenticate, authController.changeTpin);
|
||||
|
||||
router.post('/login_password', authenticate, authController.setLoginPassword);
|
||||
router.post(
|
||||
'/transaction_password',
|
||||
authenticate,
|
||||
authController.setTransactionPassword
|
||||
);
|
||||
router.post(
|
||||
'/change/login_password',
|
||||
authenticate,
|
||||
authController.changeLoginPassword
|
||||
);
|
||||
|
||||
router.get('/transaction_password', authenticate, authController.transPassword);
|
||||
router.post(
|
||||
'/transaction_password',
|
||||
authenticate,
|
||||
authController.setTransPassword
|
||||
);
|
||||
router.post(
|
||||
'/change/transaction_password',
|
||||
authenticate,
|
||||
|
||||
19
src/routes/branch.route.js
Normal file
19
src/routes/branch.route.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const express = require('express');
|
||||
const { logger } = require('../util/logger');
|
||||
const db = require('../config/db');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const branchRoute = async (req, res) => {
|
||||
try {
|
||||
const query_str = 'SELECT * FROM branches';
|
||||
const result = await db.query(query_str);
|
||||
return res.json(result.rows);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
res.status(500).json({ error: 'INTERNAL SERVER ERROR' });
|
||||
}
|
||||
};
|
||||
router.get('/', branchRoute);
|
||||
|
||||
module.exports = router;
|
||||
73
src/routes/cheque.route.js
Normal file
73
src/routes/cheque.route.js
Normal file
@@ -0,0 +1,73 @@
|
||||
const express = require('express');
|
||||
const { logger } = require('../util/logger');
|
||||
const axios = require('axios');
|
||||
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
||||
|
||||
const chequeEnquiryRoute = async (req, res) => {
|
||||
const { accountNumber, instrumentType } = req.query;
|
||||
if (!accountNumber || !instrumentType) {
|
||||
return res.status(400).json({ error: 'BAD_REQUEST' });
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8444/kccb/cheque', {
|
||||
params: { accountno: accountNumber, instrType: instrumentType },
|
||||
});
|
||||
|
||||
return res.json(response.data);
|
||||
} catch (error) {
|
||||
logger.error('Unable to fetch cheque data: ', error);
|
||||
return res.status(500).json({ error: 'INTERNAL_SERVER_ERROR' });
|
||||
}
|
||||
};
|
||||
|
||||
const chequeStopRoute = async (req, res) => {
|
||||
const {
|
||||
accountNumber,
|
||||
instrumentType,
|
||||
stopFromChequeNo,
|
||||
stopToChequeNo,
|
||||
stopIssueDate,
|
||||
stopExpiryDate,
|
||||
stopAmount,
|
||||
stopComment,
|
||||
chqIssueDate,
|
||||
} = req.body;
|
||||
|
||||
if (!accountNumber || !instrumentType || !stopFromChequeNo) {
|
||||
console.log('missing');
|
||||
return res.status(400).json({ error: 'BAD_REQUEST' });
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post(
|
||||
'http://localhost:8444/kccb/chequeSetStop',
|
||||
{
|
||||
accountno: accountNumber,
|
||||
stopFromChequeNo: stopFromChequeNo,
|
||||
instrType: instrumentType,
|
||||
stopToChequeNo: stopToChequeNo,
|
||||
stopIssueDate: stopIssueDate,
|
||||
stopExpiryDate: stopExpiryDate,
|
||||
stopAmount: stopAmount,
|
||||
stopComment: stopComment,
|
||||
chqIssueDate: chqIssueDate,
|
||||
}
|
||||
);
|
||||
|
||||
console.log('response from stop cheque api: ', response.data);
|
||||
return res.json(response.data);
|
||||
} catch (error) {
|
||||
logger.error('Unable to fetch cheque data: ', error);
|
||||
return res.status(500).json({ error: 'INTERNAL_SERVER_ERROR' });
|
||||
}
|
||||
};
|
||||
const enquiryRouter = express.Router();
|
||||
const stopRouter = express.Router();
|
||||
const router = express.Router();
|
||||
enquiryRouter.get('/enquiry', chequeEnquiryRoute);
|
||||
stopRouter.use(paymentSecretValidator);
|
||||
stopRouter.post('/stop', chequeStopRoute);
|
||||
router.use(enquiryRouter, stopRouter);
|
||||
|
||||
module.exports = router;
|
||||
@@ -8,13 +8,16 @@ const emandateData = async (req, res) => {
|
||||
return res.status(404).json({ error: 'DATA NOT FOUND FROM CLIENT' })
|
||||
try {
|
||||
const reqData = { data, mandateRequest, mandateType };
|
||||
if (customer_no) {
|
||||
reqData.customer_no = customer_no;
|
||||
}
|
||||
const response = await axios.post('http://192.168.1.166:9992/kccb/validation', reqData,
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json', },
|
||||
}
|
||||
);
|
||||
logger.info("Data validate");
|
||||
return response.data;
|
||||
logger.info(response.data, "Data validate");
|
||||
return res.json({ data: response.data });
|
||||
} catch (error) {
|
||||
logger.error(error, 'error occured while E-Mandate validation');
|
||||
return res.status(500).json({ error: 'INTERNAL_SERVER_ERROR' });
|
||||
|
||||
@@ -4,18 +4,26 @@ const adminAuthRoute = require('./admin_auth.route');
|
||||
const detailsRoute = require('./customer_details.route');
|
||||
const transactionRoute = require('./transactions.route');
|
||||
const authenticate = require('../middlewares/auth.middleware');
|
||||
const adminAuthenticate = require('../middlewares/admin.middleware');
|
||||
const transferRoute = require('./transfer.route');
|
||||
const beneficiaryRoute = require('./beneficiary.route');
|
||||
const neftRoute = require('./neft.route');
|
||||
const rtgsRoute = require('./rtgs.route');
|
||||
const impsRoute = require('./imps.route');
|
||||
const branchRoute = require('./branch.route');
|
||||
const atmRoute = require('./atm.route');
|
||||
const { npciResponse } = require('../controllers/npci.controller');
|
||||
const {
|
||||
simDetailsResponse,
|
||||
simDetailsRequest,
|
||||
} = require('./sim_verfify.route.js');
|
||||
const otp = require('./otp.route');
|
||||
const reports = require('./report.route');
|
||||
const eMandate = require('./emandate.route');
|
||||
const chequeRoute = require('./cheque.route');
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/auth', authRoute);
|
||||
router.use('/auth/admin', adminAuthRoute);
|
||||
router.use('/customer', authenticate, detailsRoute);
|
||||
router.use('/transactions/account/:accountNo', authenticate, transactionRoute);
|
||||
router.use('/payment/transfer', authenticate, transferRoute);
|
||||
@@ -24,7 +32,18 @@ router.use('/payment/rtgs', authenticate, rtgsRoute);
|
||||
router.use('/payment/imps', authenticate, impsRoute);
|
||||
router.use('/beneficiary', authenticate, beneficiaryRoute);
|
||||
router.use('/npci/beneficiary-response', npciResponse);
|
||||
router.use('/otp', otp);
|
||||
router.use('/e-mandate', authenticate, eMandate);
|
||||
router.use('/branch', authenticate, branchRoute);
|
||||
router.use('/atm', authenticate, atmRoute);
|
||||
router.use('/cheque', authenticate, chequeRoute);
|
||||
|
||||
// OTP
|
||||
router.use('/otp', otp);
|
||||
|
||||
// Admin APIs
|
||||
router.use('/auth/admin', adminAuthRoute);
|
||||
router.use('/report', adminAuthenticate, reports);
|
||||
router.post('/sim-details', simDetailsResponse);
|
||||
router.post('/sim-details-verify', simDetailsRequest);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
12
src/routes/report.route.js
Normal file
12
src/routes/report.route.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const reportController = require('../controllers/report.controller');
|
||||
const express = require('express');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/active_users', reportController.active_users);
|
||||
router.post('/in-active_users', reportController.inactive_users);
|
||||
router.post('/transaction_report', reportController.getTransactions);
|
||||
router.post('/failed_transaction_report', reportController.getFailedTransactions);
|
||||
router.post('/not_logged_in', reportController.getDetailsOfNotLoginWithinDuration);
|
||||
|
||||
module.exports = router;
|
||||
69
src/routes/sim_verfify.route.js
Normal file
69
src/routes/sim_verfify.route.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const db = require('../config/db');
|
||||
const { getJson, setJson } = require('../config/redis');
|
||||
const { logger } = require('../util/logger');
|
||||
const customerController = require('../controllers/customer_details.controller');
|
||||
|
||||
async function simDetailsResponse(req, res) {
|
||||
const { phoneNo, uuid } = req.body;
|
||||
try {
|
||||
console.log(`phone no from sms: ${phoneNo}`);
|
||||
console.log(`message body from sms: ${uuid}`);
|
||||
await setJson(uuid, phoneNo);
|
||||
} catch (error) {
|
||||
logger.error(error, 'error processing sim details response');
|
||||
}
|
||||
res.json({ message: 'OK' });
|
||||
}
|
||||
|
||||
async function simDetailsRequest(req, res) {
|
||||
const { cifNo, uuid } = req.body;
|
||||
try {
|
||||
const customerDetails = await customerController.getDetails(cifNo);
|
||||
const phoneNo = customerDetails[0].mobileno?.slice(-10);
|
||||
const phoneNoFromVendor = await pollRedisKey(uuid);
|
||||
if (!phoneNoFromVendor) {
|
||||
return res.json({ error: 'Could not verify phone number' });
|
||||
}
|
||||
const strippedPhoneNo = phoneNoFromVendor.slice(-10);
|
||||
console.log('phone no from CBS: ', phoneNo);
|
||||
console.log('phone no from SIM: ', strippedPhoneNo);
|
||||
if (phoneNo === strippedPhoneNo) {
|
||||
return res.json({ status: 'VERIFIED' });
|
||||
}
|
||||
return res.json({ status: 'NOT_VERIFIED' });
|
||||
} catch (error) {
|
||||
logger.error(error, 'sim verification failed');
|
||||
res.status(500).json({ error: 'SIM verification failed' });
|
||||
}
|
||||
}
|
||||
|
||||
async function pollRedisKey(key) {
|
||||
const timeout = 2 * 60 * 1000;
|
||||
const interval = 2000;
|
||||
const startTime = Date.now();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const poll = async () => {
|
||||
try {
|
||||
const phoneNo = await getJson(key);
|
||||
if (phoneNo !== null) {
|
||||
console.log(phoneNo, 'payload from redis');
|
||||
return resolve(phoneNo);
|
||||
}
|
||||
|
||||
if (Date.now() - startTime >= timeout) {
|
||||
return resolve(null);
|
||||
}
|
||||
|
||||
console.log('not found retrying for uuid');
|
||||
|
||||
setTimeout(poll, interval);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
poll();
|
||||
});
|
||||
}
|
||||
module.exports = { simDetailsResponse, simDetailsRequest };
|
||||
@@ -38,10 +38,19 @@ async function getCustomerDetails(customerNo) {
|
||||
}
|
||||
|
||||
async function getCustomerDetailsFromDB(customerNo) {
|
||||
const result = await db.query('SELECT customer_no,created_at,last_login,is_first_login,ib_access_level,mb_access_level FROM users WHERE customer_no = $1', [
|
||||
const result = await db.query(
|
||||
'SELECT customer_no,created_at,last_login,is_first_login,ib_access_level,mb_access_level,inb_limit_amount,mobile_limit_amount,locked FROM users WHERE customer_no = $1 or preferred_name= $1', [
|
||||
customerNo,
|
||||
]);
|
||||
return result.rows[0];
|
||||
}
|
||||
|
||||
module.exports = { validateAdmin, findAdminByUserName, getCustomerDetails,getCustomerDetailsFromDB };
|
||||
async function updateUserLockStatus(customerNo ,locked ,adminUserName) {
|
||||
const result = await db.query(
|
||||
'Update users set locked =$2 ,unlocked_by=$3 WHERE customer_no = $1 or preferred_name= $1', [
|
||||
customerNo, locked ,adminUserName
|
||||
]);
|
||||
return result.rows[0];
|
||||
}
|
||||
|
||||
module.exports = { validateAdmin, findAdminByUserName, getCustomerDetails, getCustomerDetailsFromDB ,updateUserLockStatus };
|
||||
|
||||
106
src/services/report.service.js
Normal file
106
src/services/report.service.js
Normal file
@@ -0,0 +1,106 @@
|
||||
const db = require('../config/db');
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
async function total_users(from_date, to_date) {
|
||||
try {
|
||||
const result = await db.query(
|
||||
`SELECT * FROM users WHERE created_at BETWEEN $1 AND $2`,
|
||||
[from_date, to_date]
|
||||
);
|
||||
logger.info("data fetch for users");
|
||||
return result.rows;
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch data');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function getTransactions(filters) {
|
||||
try {
|
||||
const { trx_type, from_date, to_date, client, amount_min, amount_max, customer_no } = filters;
|
||||
|
||||
let query = `SELECT * FROM transactions WHERE trx_type = $1 AND created_at >= $2 AND created_at < $3`;
|
||||
const params = [trx_type, from_date, to_date];
|
||||
let paramIndex = 4;
|
||||
|
||||
if (client) {
|
||||
query += ` AND client = $${paramIndex++}`;
|
||||
params.push(client);
|
||||
}
|
||||
|
||||
if (amount_min && amount_max) {
|
||||
query += ` AND amount BETWEEN $${paramIndex++} AND $${paramIndex++}`;
|
||||
params.push(amount_min, amount_max);
|
||||
} else if (amount_min) {
|
||||
query += ` AND amount >= $${paramIndex++}`;
|
||||
params.push(amount_min);
|
||||
} else if (amount_max) {
|
||||
query += ` AND amount <= $${paramIndex++}`;
|
||||
params.push(amount_max);
|
||||
}
|
||||
|
||||
if (customer_no) {
|
||||
query += ` AND customer_no = $${paramIndex++}`;
|
||||
params.push(customer_no);
|
||||
}
|
||||
|
||||
query += ` ORDER BY created_at DESC`;
|
||||
|
||||
const result = await db.query(query, params);
|
||||
logger.info(`Fetched ${result.rows.length} transactions`);
|
||||
return result.rows;
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch transactions');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function getFailedTransactions(filters) {
|
||||
try {
|
||||
const { from_date, to_date, customer_no } = filters;
|
||||
|
||||
let query = `
|
||||
SELECT *
|
||||
FROM transactions
|
||||
WHERE created_at >= $1
|
||||
AND created_at < $2
|
||||
AND status LIKE 'FAILURE%'`;
|
||||
|
||||
// params should match $1, $2, etc.
|
||||
const params = [from_date, to_date];
|
||||
let paramIndex = params.length + 1; // start from 3
|
||||
|
||||
if (customer_no) {
|
||||
query += ` AND customer_no = $${paramIndex}`;
|
||||
params.push(customer_no);
|
||||
}
|
||||
|
||||
query += ` ORDER BY created_at DESC`;
|
||||
console.log(query);
|
||||
|
||||
const result = await db.query(query, params);
|
||||
logger.info(`Fetched ${result.rows.length} failed transactions`);
|
||||
return result.rows;
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err, 'Failed to fetch failed transactions');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function getNotLogin(duration) {
|
||||
try {
|
||||
const result = await db.query(
|
||||
`SELECT * FROM users WHERE last_login <= NOW() - ($1 || ' month')::interval`,
|
||||
[duration]
|
||||
);
|
||||
logger.info("data fetch for users who have not logged-in in mentioned duration");
|
||||
return result.rows;
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to fetch not logged-in users data');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { total_users, getTransactions, getFailedTransactions, getNotLogin };
|
||||
@@ -59,6 +59,12 @@ const templates = {
|
||||
|
||||
TLIMIT_SET: (amount) =>
|
||||
`Dear Customer,Your transaction limit for Internet Banking is set to Rs ${amount}. -KCCB`,
|
||||
|
||||
LPWORD_CHANGE:
|
||||
`Dear Customer, Your Login password has been successfully updated. If you did not initiate this, please contact your nearest branch immediately. -KCCB`,
|
||||
|
||||
TPWORD_CHANGE:
|
||||
`Dear Customer, Your transaction password has been successfully updated. If you did not initiate this, please contact your nearest branch immediately. -KCCB`,
|
||||
};
|
||||
|
||||
module.exports = templates;
|
||||
Reference in New Issue
Block a user