Compare commits
31 Commits
feat-daily
...
fetch-from
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e831acfe2 | |||
| bf06706b29 | |||
| 7e162e741d | |||
| a04830cdb2 | |||
| 12f0881c9b | |||
| b0c9cb8038 | |||
| a8a576f5c1 | |||
| 4c63ccf3ae | |||
| 759869b0e3 | |||
| 60cb0076f1 | |||
| b68c8a08c2 | |||
| 739f2737ba | |||
| 6b80ef83b4 | |||
| a28c08f8b2 | |||
| f922179765 | |||
| b9c9d35f74 | |||
| c39492edde | |||
| 3f86697f6b | |||
| c021d6033c | |||
| 55c822487b | |||
| 0164aad402 | |||
| f7bc0f6785 | |||
| 95fc26ef6b | |||
| caef3bd690 | |||
| 2c210f07c7 | |||
| ea1d7dae85 | |||
| a53bca4a34 | |||
| 43cce9f04a | |||
| 05db88f409 | |||
| 2cc1f3fcad | |||
| f807f62660 |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,8 +1,10 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"emandate",
|
||||||
"MPIN",
|
"MPIN",
|
||||||
"occured",
|
"occured",
|
||||||
"otpgenerator",
|
"otpgenerator",
|
||||||
|
"TLIMIT",
|
||||||
"tpassword",
|
"tpassword",
|
||||||
"tpin",
|
"tpin",
|
||||||
"TPWORD"
|
"TPWORD"
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ dotenv.config({ path: path.resolve(__dirname, '../../.env') });
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
port: process.env.PORT || 8080,
|
port: process.env.PORT || 8080,
|
||||||
dbUrl: process.env.DATABASE_URL,
|
dbUrl: process.env.DATABASE_URL,
|
||||||
|
redisUrl: process.env.REDIS_URL,
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ const { comparePassword } = require('../util/hash');
|
|||||||
const customerController = require('../controllers/customer_details.controller.js');
|
const customerController = require('../controllers/customer_details.controller.js');
|
||||||
const { setJson, getJson } = require('../config/redis');
|
const { setJson, getJson } = require('../config/redis');
|
||||||
|
|
||||||
|
|
||||||
async function login(req, res) {
|
async function login(req, res) {
|
||||||
let { customerNo, userName, password, otp } = req.body;
|
let { customerNo, userName, password, otp } = req.body;
|
||||||
const loginType = req.headers['x-login-type'] || 'standard';
|
const loginType = req.headers['x-login-type'] || 'standard';
|
||||||
|
|
||||||
if ((!customerNo && !userName) || !password) {
|
if ((!customerNo && !userName) || !password) {
|
||||||
return res.status(400).json({ error: 'customerNo and password are required' });
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ error: 'customerNo and password are required' });
|
||||||
}
|
}
|
||||||
const currentTime = new Date().toISOString();
|
const currentTime = new Date().toISOString();
|
||||||
const MAX_ATTEMPTS = 3; // Max invalid attempts before lock
|
const MAX_ATTEMPTS = 3; // Max invalid attempts before lock
|
||||||
@@ -23,24 +24,30 @@ async function login(req, res) {
|
|||||||
const blockedKey = `login:blocked:${customerNo}`;
|
const blockedKey = `login:blocked:${customerNo}`;
|
||||||
const attemptsKey = `login:attempts:${customerNo}`;
|
const attemptsKey = `login:attempts:${customerNo}`;
|
||||||
if (!customerNo && userName) {
|
if (!customerNo && userName) {
|
||||||
const result = await db.query('SELECT * FROM users WHERE preferred_name = $1', [
|
const result = await db.query(
|
||||||
userName,
|
'SELECT * FROM users WHERE preferred_name = $1',
|
||||||
]);
|
[userName]
|
||||||
|
);
|
||||||
if (result.rows.length === 0) {
|
if (result.rows.length === 0) {
|
||||||
logger.error("Customer not found with this user name.");
|
logger.error('Customer not found with this user name.');
|
||||||
return res.status(404).json({ error: 'No user found with this username.' });
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ error: 'No user found with this username.' });
|
||||||
}
|
}
|
||||||
logger.info("Customer found with user name.");
|
logger.info('Customer found with user name.');
|
||||||
customerNo = result.rows[0].customer_no;
|
customerNo = result.rows[0].customer_no;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userCheck = await authService.findUserByCustomerNo(customerNo);
|
const userCheck = await authService.findUserByCustomerNo(customerNo);
|
||||||
|
if (!userCheck) {
|
||||||
|
return res.status(404).json({ error: 'customer not found' });
|
||||||
|
}
|
||||||
|
|
||||||
if (loginType.toUpperCase() === 'IB') {
|
if (loginType.toUpperCase() === 'IB') {
|
||||||
// check DB locked flag
|
// check DB locked flag
|
||||||
if (userCheck && userCheck.locked) {
|
if (userCheck && userCheck.locked) {
|
||||||
await setJson(blockedKey, true, BLOCK_DURATION);
|
await setJson(blockedKey, true, BLOCK_DURATION);
|
||||||
logger.error("USER Account Locked");
|
logger.error('USER Account Locked');
|
||||||
return res.status(423).json({
|
return res.status(423).json({
|
||||||
error: 'Your account is locked. Please contact the administrator.',
|
error: 'Your account is locked. Please contact the administrator.',
|
||||||
});
|
});
|
||||||
@@ -48,9 +55,13 @@ async function login(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Step 2: Check migration status
|
// --- Step 2: Check migration status
|
||||||
const isMigratedUser = await authService.isMigratedUser(customerNo);
|
const migratedPassword = `${userCheck.customer_no}@KCCB`;
|
||||||
if (isMigratedUser)
|
const isMigratedUser = userCheck.password_hash === migratedPassword;
|
||||||
|
if (isMigratedUser) {
|
||||||
|
if (password !== migratedPassword)
|
||||||
|
return res.status(401).json({ error: 'Invalid credentials.' });
|
||||||
return res.status(401).json({ error: 'MIGRATED_USER_HAS_NO_PASSWORD' });
|
return res.status(401).json({ error: 'MIGRATED_USER_HAS_NO_PASSWORD' });
|
||||||
|
}
|
||||||
|
|
||||||
// --- Step 3: Validate credentials ---
|
// --- Step 3: Validate credentials ---
|
||||||
const user = await authService.validateUser(customerNo, password);
|
const user = await authService.validateUser(customerNo, password);
|
||||||
@@ -61,12 +72,16 @@ async function login(req, res) {
|
|||||||
attempts += 1;
|
attempts += 1;
|
||||||
|
|
||||||
if (attempts >= MAX_ATTEMPTS) {
|
if (attempts >= MAX_ATTEMPTS) {
|
||||||
await db.query('UPDATE users SET locked = true WHERE customer_no = $1', [customerNo]);
|
await db.query(
|
||||||
|
'UPDATE users SET locked = true WHERE customer_no = $1',
|
||||||
|
[customerNo]
|
||||||
|
);
|
||||||
await setJson(blockedKey, true, BLOCK_DURATION);
|
await setJson(blockedKey, true, BLOCK_DURATION);
|
||||||
await setJson(attemptsKey, 0);
|
await setJson(attemptsKey, 0);
|
||||||
|
|
||||||
return res.status(423).json({
|
return res.status(423).json({
|
||||||
error: 'Your account has been locked due to multiple failed login attempts. Please contact the administrator.',
|
error:
|
||||||
|
'Your account has been locked due to multiple failed login attempts. Please contact the administrator.',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await setJson(attemptsKey, attempts, BLOCK_DURATION);
|
await setJson(attemptsKey, attempts, BLOCK_DURATION);
|
||||||
@@ -107,6 +122,8 @@ async function login(req, res) {
|
|||||||
// --- Step 7: Generate token and update last login ---
|
// --- Step 7: Generate token and update last login ---
|
||||||
const token = generateToken(user.customer_no);
|
const token = generateToken(user.customer_no);
|
||||||
const loginPswExpiry = user.password_hash_expiry;
|
const loginPswExpiry = user.password_hash_expiry;
|
||||||
|
const mobileTncAccepted = user.tnc_mobile;
|
||||||
|
const tnc = { mobile: mobileTncAccepted };
|
||||||
const rights = {
|
const rights = {
|
||||||
ibAccess: user.ib_access_level,
|
ibAccess: user.ib_access_level,
|
||||||
mbAccess: user.mb_access_level,
|
mbAccess: user.mb_access_level,
|
||||||
@@ -116,7 +133,7 @@ async function login(req, res) {
|
|||||||
customerNo,
|
customerNo,
|
||||||
]);
|
]);
|
||||||
logger.info(`Login successful | Type: ${loginType}`);
|
logger.info(`Login successful | Type: ${loginType}`);
|
||||||
return res.json({ token, FirstTimeLogin, loginPswExpiry, rights });
|
return res.json({ token, FirstTimeLogin, loginPswExpiry, rights, tnc });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err, `login failed | Type: ${loginType}`);
|
logger.error(err, `login failed | Type: ${loginType}`);
|
||||||
return res.status(500).json({ error: 'something went wrong' });
|
return res.status(500).json({ error: 'something went wrong' });
|
||||||
@@ -161,7 +178,28 @@ async function setTpin(req, res) {
|
|||||||
const { tpin } = req.body;
|
const { tpin } = req.body;
|
||||||
if (!/^\d{6}$/.test(tpin))
|
if (!/^\d{6}$/.test(tpin))
|
||||||
return res.status(400).json({ error: 'INVALID_TPIN_FORMAT' });
|
return res.status(400).json({ error: 'INVALID_TPIN_FORMAT' });
|
||||||
authService.setTpin(customerNo, tpin);
|
await authService.setTpin(customerNo, tpin);
|
||||||
|
return res.json({ message: 'TPIN_SET' });
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return res.status(500).json({ error: 'SOMETHING_WENT_WRONG' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function changeTpin(req, res) {
|
||||||
|
const customerNo = req.user;
|
||||||
|
try {
|
||||||
|
const user = await authService.findUserByCustomerNo(customerNo);
|
||||||
|
if (!user) return res.status(404).json({ error: 'USER_NOT_FOUND' });
|
||||||
|
if (!user.tpin)
|
||||||
|
return res.status(400).json({ error: 'USER_DOESNT_HAVE_A_TPIN' });
|
||||||
|
const { oldTpin, newTpin } = req.body;
|
||||||
|
const isMatch = await comparePassword(oldTpin, user.tpin);
|
||||||
|
if (!isMatch) return res.status(400).json({ error: 'TPIN_DOESNT_MATCH' });
|
||||||
|
|
||||||
|
if (!/^\d{6}$/.test(newTpin))
|
||||||
|
return res.status(400).json({ error: 'INVALID_TPIN_FORMAT' });
|
||||||
|
await authService.setTpin(customerNo, newTpin);
|
||||||
return res.json({ message: 'TPIN_SET' });
|
return res.json({ message: 'TPIN_SET' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
@@ -298,18 +336,25 @@ async function setUserName(req, res) {
|
|||||||
return res.json({ message: 'All set! Your username has been saved.' });
|
return res.json({ message: 'All set! Your username has been saved.' });
|
||||||
}
|
}
|
||||||
if (userNameIsExits) {
|
if (userNameIsExits) {
|
||||||
const historyRes = await db.query('SELECT preferred_name FROM preferred_name_history WHERE customer_no = $1 ORDER BY changed_at DESC LIMIT 5',
|
const historyRes = await db.query(
|
||||||
|
'SELECT preferred_name FROM preferred_name_history WHERE customer_no = $1 ORDER BY changed_at DESC LIMIT 5',
|
||||||
[customerNo]
|
[customerNo]
|
||||||
);
|
);
|
||||||
// maximum 5 times can changed username
|
// maximum 5 times can changed username
|
||||||
const history = historyRes.rows.map((r) => r.preferred_name.toLowerCase());
|
const history = historyRes.rows.map((r) =>
|
||||||
|
r.preferred_name.toLowerCase()
|
||||||
|
);
|
||||||
if (history.length >= 5) {
|
if (history.length >= 5) {
|
||||||
return res.status(429).json({ error: "Preferred name change limit reached -5 times" });
|
return res
|
||||||
|
.status(429)
|
||||||
|
.json({ error: 'Preferred name change limit reached -5 times' });
|
||||||
}
|
}
|
||||||
// Cannot match last 2
|
// Cannot match last 2
|
||||||
const lastTwo = history.slice(0, 2);
|
const lastTwo = history.slice(0, 2);
|
||||||
if (lastTwo.includes(user_name.toLowerCase())) {
|
if (lastTwo.includes(user_name.toLowerCase())) {
|
||||||
return res.status(409).json({ error: "Preferred name cannot match last 2 preferred names" });
|
return res.status(409).json({
|
||||||
|
error: 'Preferred name cannot match last 2 preferred names',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
await authService.setUserName(customerNo, user_name);
|
await authService.setUserName(customerNo, user_name);
|
||||||
logger.info('User name has been updated.');
|
logger.info('User name has been updated.');
|
||||||
@@ -321,10 +366,34 @@ async function setUserName(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getTncAcceptanceFlag(req, res) {
|
||||||
|
try {
|
||||||
|
const flag = await authService.getTncFlag(req.user, req.client);
|
||||||
|
res.json({ tnc_accepted: flag });
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, 'error occured while getting tnc flag');
|
||||||
|
res.status(500).json({ error: 'INTERNAL SERVER ERROR' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setTncAcceptanceFlag(req, res) {
|
||||||
|
try {
|
||||||
|
const { flag } = req.body;
|
||||||
|
if (flag !== 'Y' && flag !== 'N')
|
||||||
|
res.status(400).json({ error: 'invalid value for flag' });
|
||||||
|
await authService.setTncFlag(req.user, req.client, flag);
|
||||||
|
return res.json({ message: 'SUCCESS' });
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, 'error occured while updating tnc flag');
|
||||||
|
res.status(500).json({ error: 'INTERNAL SERVER ERROR' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
login,
|
login,
|
||||||
tpin,
|
tpin,
|
||||||
setTpin,
|
setTpin,
|
||||||
|
changeTpin,
|
||||||
setLoginPassword,
|
setLoginPassword,
|
||||||
setTransactionPassword,
|
setTransactionPassword,
|
||||||
fetchUserDetails,
|
fetchUserDetails,
|
||||||
@@ -332,4 +401,6 @@ module.exports = {
|
|||||||
changeTransPassword,
|
changeTransPassword,
|
||||||
isUserNameExits,
|
isUserNameExits,
|
||||||
setUserName,
|
setUserName,
|
||||||
|
getTncAcceptanceFlag,
|
||||||
|
setTncAcceptanceFlag,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ const { logger } = require('../util/logger');
|
|||||||
|
|
||||||
async function npciResponse(req, res) {
|
async function npciResponse(req, res) {
|
||||||
const { resp } = req.body;
|
const { resp } = req.body;
|
||||||
logger.info(resp, 'received from NPCI');
|
logger.info(req.body, 'received response from NPCI');
|
||||||
if (resp.status === 'Success') {
|
if (resp === 'SUCCESS') {
|
||||||
await handleNPCISuccess(resp);
|
await handleNPCISuccess(req.body);
|
||||||
} else {
|
} else {
|
||||||
await handleNPCIFailure(resp);
|
await handleNPCIFailure(req.body);
|
||||||
}
|
}
|
||||||
res.send('ok');
|
res.send('ok');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,13 @@ async function SendOtp(req, res) {
|
|||||||
case 'USERNAME_SAVED':
|
case 'USERNAME_SAVED':
|
||||||
message = templates.USERNAME_SAVED(PreferName);
|
message = templates.USERNAME_SAVED(PreferName);
|
||||||
break;
|
break;
|
||||||
|
case 'TLIMIT':
|
||||||
|
otp = generateOTP(6);
|
||||||
|
message = templates.TLIMIT(otp);
|
||||||
|
break;
|
||||||
|
case 'TLIMIT_SET':
|
||||||
|
message = templates.TLIMIT_SET(amount);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Invalid OTP type' });
|
return res.status(400).json({ error: 'Invalid OTP type' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
const { logger } = require('../util/logger');
|
const { logger } = require('../util/logger');
|
||||||
|
|
||||||
function verifyClient(req, res, next) {
|
function verifyClient(req, res, next) {
|
||||||
|
console.log('printing headers');
|
||||||
|
console.log(req.headers);
|
||||||
const clientHeader = req.headers['x-login-type'];
|
const clientHeader = req.headers['x-login-type'];
|
||||||
|
|
||||||
if (!clientHeader || (clientHeader !== 'MB' && clientHeader !== 'IB')) {
|
if (!clientHeader || (clientHeader !== 'MB' && clientHeader !== 'IB' && clientHeader !== 'NPCI' && clientHeader !== 'eMandate' && clientHeader !=='Admin')) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Invalid or missing client header. Expected 'MB' or 'IB'. Found ${clientHeader}`
|
`Invalid or missing client header. Expected 'MB' or 'IB'. Found ${clientHeader}`
|
||||||
);
|
);
|
||||||
|
|||||||
29
src/middlewares/cooldown.middleware.js
Normal file
29
src/middlewares/cooldown.middleware.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
const { logger } = require('../util/logger');
|
||||||
|
const { getSingleBeneficiary } = require('../services/beneficiary.service');
|
||||||
|
|
||||||
|
async function checkBeneficiaryCooldown(req, res, next) {
|
||||||
|
const cooldownTime = parseInt(
|
||||||
|
process.env.BENEFICIARY_COOLDOWN_TIME || '60',
|
||||||
|
10
|
||||||
|
);
|
||||||
|
const customerNo = req.user;
|
||||||
|
const { toAccount } = req.body;
|
||||||
|
const beneficiary = await getSingleBeneficiary(customerNo, toAccount);
|
||||||
|
|
||||||
|
if (beneficiary) {
|
||||||
|
const now = new Date();
|
||||||
|
const cooldownPeriod = new Date(now.getTime() - cooldownTime * 60 * 1000);
|
||||||
|
const createdAt = new Date(beneficiary['created_at']);
|
||||||
|
if (createdAt > cooldownPeriod) {
|
||||||
|
const remaining = (now - createdAt) / (60 * 1000);
|
||||||
|
logger.warn('TRANSACTION_FAILED BENEFICIARY_COOLDOWN_ACTIVE');
|
||||||
|
return res.status(403).json({
|
||||||
|
remaining,
|
||||||
|
error: 'beneficiary cooldown period active',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { checkBeneficiaryCooldown };
|
||||||
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;
|
||||||
@@ -8,12 +8,27 @@ router.post('/login', authController.login);
|
|||||||
router.get('/user_details', authenticate, authController.fetchUserDetails);
|
router.get('/user_details', authenticate, authController.fetchUserDetails);
|
||||||
router.get('/tpin', authenticate, authController.tpin);
|
router.get('/tpin', authenticate, authController.tpin);
|
||||||
router.post('/tpin', authenticate, authController.setTpin);
|
router.post('/tpin', authenticate, authController.setTpin);
|
||||||
|
router.post('/change/tpin', authenticate, authController.changeTpin);
|
||||||
router.post('/login_password', authenticate, authController.setLoginPassword);
|
router.post('/login_password', authenticate, authController.setLoginPassword);
|
||||||
router.post('/transaction_password',authenticate,authController.setTransactionPassword);
|
router.post(
|
||||||
router.post('/change/login_password',authenticate,authController.changeLoginPassword);
|
'/transaction_password',
|
||||||
router.post('/change/transaction_password',authenticate,authController.changeTransPassword);
|
authenticate,
|
||||||
|
authController.setTransactionPassword
|
||||||
|
);
|
||||||
|
router.post(
|
||||||
|
'/change/login_password',
|
||||||
|
authenticate,
|
||||||
|
authController.changeLoginPassword
|
||||||
|
);
|
||||||
|
router.post(
|
||||||
|
'/change/transaction_password',
|
||||||
|
authenticate,
|
||||||
|
authController.changeTransPassword
|
||||||
|
);
|
||||||
router.get('/user_name', authenticate, authController.isUserNameExits);
|
router.get('/user_name', authenticate, authController.isUserNameExits);
|
||||||
router.post('/user_name', authenticate, authController.setUserName);
|
router.post('/user_name', authenticate, authController.setUserName);
|
||||||
|
|
||||||
|
router.get('/tnc', authenticate, authController.getTncAcceptanceFlag);
|
||||||
|
router.post('/tnc', authenticate, authController.setTncAcceptanceFlag);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
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;
|
||||||
24
src/routes/emandate.route.js
Normal file
24
src/routes/emandate.route.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const axios = require('axios');
|
||||||
|
const { logger } = require('../util/logger');
|
||||||
|
const router = express.Router();
|
||||||
|
const emandateData = async (req, res) => {
|
||||||
|
const { data, mandateRequest, mandateType } = req.body;
|
||||||
|
if (!data || !mandateRequest | !mandateType)
|
||||||
|
return res.status(404).json({ error: 'DATA NOT FOUND FROM CLIENT' })
|
||||||
|
try {
|
||||||
|
const reqData = { data, mandateRequest, mandateType };
|
||||||
|
const response = await axios.post('http://192.168.1.166:9992/kccb/validation', reqData,
|
||||||
|
{
|
||||||
|
headers: { 'Content-Type': 'application/json', },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
router.post('/validation', emandateData);
|
||||||
|
module.exports = router;
|
||||||
@@ -4,9 +4,17 @@ const { logger } = require('../util/logger');
|
|||||||
const impsValidator = require('../validators/imps.validator');
|
const impsValidator = require('../validators/imps.validator');
|
||||||
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
||||||
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
||||||
|
const {
|
||||||
|
checkBeneficiaryCooldown,
|
||||||
|
} = require('../middlewares/cooldown.middleware');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.use(impsValidator, paymentSecretValidator, checkLimit);
|
router.use(
|
||||||
|
impsValidator,
|
||||||
|
paymentSecretValidator,
|
||||||
|
checkLimit,
|
||||||
|
checkBeneficiaryCooldown
|
||||||
|
);
|
||||||
|
|
||||||
const impsRoute = async (req, res) => {
|
const impsRoute = async (req, res) => {
|
||||||
const { fromAccount, toAccount, ifscCode, amount, beneficiaryName, remarks } =
|
const { fromAccount, toAccount, ifscCode, amount, beneficiaryName, remarks } =
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ const beneficiaryRoute = require('./beneficiary.route');
|
|||||||
const neftRoute = require('./neft.route');
|
const neftRoute = require('./neft.route');
|
||||||
const rtgsRoute = require('./rtgs.route');
|
const rtgsRoute = require('./rtgs.route');
|
||||||
const impsRoute = require('./imps.route');
|
const impsRoute = require('./imps.route');
|
||||||
|
const branchRoute = require('./branch.route');
|
||||||
|
const atmRoute = require('./atm.route');
|
||||||
const { npciResponse } = require('../controllers/npci.controller');
|
const { npciResponse } = require('../controllers/npci.controller');
|
||||||
const otp = require('./otp.route');
|
const otp = require('./otp.route');
|
||||||
|
const eMandate = require('./emandate.route');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.use('/auth', authRoute);
|
router.use('/auth', authRoute);
|
||||||
@@ -25,5 +27,8 @@ router.use('/payment/imps', authenticate, impsRoute);
|
|||||||
router.use('/beneficiary', authenticate, beneficiaryRoute);
|
router.use('/beneficiary', authenticate, beneficiaryRoute);
|
||||||
router.use('/npci/beneficiary-response', npciResponse);
|
router.use('/npci/beneficiary-response', npciResponse);
|
||||||
router.use('/otp', otp);
|
router.use('/otp', otp);
|
||||||
|
router.use('/e-mandate', authenticate, eMandate);
|
||||||
|
router.use('/branch', authenticate, branchRoute);
|
||||||
|
router.use('/atm', authenticate, atmRoute);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -4,9 +4,17 @@ const { logger } = require('../util/logger');
|
|||||||
const neftValidator = require('../validators/neft.validator.js');
|
const neftValidator = require('../validators/neft.validator.js');
|
||||||
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
||||||
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
||||||
|
const {
|
||||||
|
checkBeneficiaryCooldown,
|
||||||
|
} = require('../middlewares/cooldown.middleware');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.use(neftValidator, paymentSecretValidator, checkLimit);
|
router.use(
|
||||||
|
neftValidator,
|
||||||
|
paymentSecretValidator,
|
||||||
|
checkLimit,
|
||||||
|
checkBeneficiaryCooldown
|
||||||
|
);
|
||||||
|
|
||||||
const neftRoute = async (req, res) => {
|
const neftRoute = async (req, res) => {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -4,9 +4,17 @@ const { logger } = require('../util/logger');
|
|||||||
const rtgsValidator = require('../validators/rtgs.validator.js');
|
const rtgsValidator = require('../validators/rtgs.validator.js');
|
||||||
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
const paymentSecretValidator = require('../validators/payment.secret.validator');
|
||||||
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
||||||
|
const {
|
||||||
|
checkBeneficiaryCooldown,
|
||||||
|
} = require('../middlewares/cooldown.middleware');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.use(rtgsValidator, paymentSecretValidator, checkLimit);
|
router.use(
|
||||||
|
rtgsValidator,
|
||||||
|
paymentSecretValidator,
|
||||||
|
checkLimit,
|
||||||
|
checkBeneficiaryCooldown
|
||||||
|
);
|
||||||
|
|
||||||
const rtgsRoute = async (req, res) => {
|
const rtgsRoute = async (req, res) => {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -4,9 +4,17 @@ const express = require('express');
|
|||||||
const transferValidator = require('../validators/transfer.validator');
|
const transferValidator = require('../validators/transfer.validator');
|
||||||
const passwordValidator = require('../validators/payment.secret.validator.js');
|
const passwordValidator = require('../validators/payment.secret.validator.js');
|
||||||
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
const { checkLimit } = require('../middlewares/limitCheck.middleware');
|
||||||
|
const {
|
||||||
|
checkBeneficiaryCooldown,
|
||||||
|
} = require('../middlewares/cooldown.middleware');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.use(passwordValidator, transferValidator, checkLimit);
|
router.use(
|
||||||
|
passwordValidator,
|
||||||
|
transferValidator,
|
||||||
|
checkLimit,
|
||||||
|
checkBeneficiaryCooldown
|
||||||
|
);
|
||||||
|
|
||||||
const transferRoute = async (req, res) => {
|
const transferRoute = async (req, res) => {
|
||||||
const { fromAccount, toAccount, toAccountType, amount, remarks } = req.body;
|
const { fromAccount, toAccount, toAccountType, amount, remarks } = req.body;
|
||||||
|
|||||||
@@ -127,16 +127,16 @@ async function changeTransPassword(customerNo, trans_psw) {
|
|||||||
|
|
||||||
async function CheckUserName(customerNo) {
|
async function CheckUserName(customerNo) {
|
||||||
try {
|
try {
|
||||||
const result = await db.query('SELECT preferred_name from users WHERE customer_no = $1',
|
const result = await db.query(
|
||||||
|
'SELECT preferred_name from users WHERE customer_no = $1',
|
||||||
[customerNo]
|
[customerNo]
|
||||||
);
|
);
|
||||||
if (result.rows.length > 0) {
|
if (result.rows.length > 0) {
|
||||||
return result.rows[0].preferred_name;;
|
return result.rows[0].preferred_name;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`error occurred while fetch the preferred name ${error.message}`
|
`error occurred while fetch the preferred name ${error.message}`
|
||||||
);
|
);
|
||||||
@@ -150,12 +150,12 @@ async function setUserName(customerNo, username) {
|
|||||||
'UPDATE users SET preferred_name = $1 ,updated_at = $2 WHERE customer_no = $3',
|
'UPDATE users SET preferred_name = $1 ,updated_at = $2 WHERE customer_no = $3',
|
||||||
[username, currentTime, customerNo]
|
[username, currentTime, customerNo]
|
||||||
);
|
);
|
||||||
logger.info("user table updated");
|
logger.info('user table updated');
|
||||||
await db.query(
|
await db.query(
|
||||||
"INSERT INTO preferred_name_history (customer_no, preferred_name) VALUES ($1, $2)",
|
'INSERT INTO preferred_name_history (customer_no, preferred_name) VALUES ($1, $2)',
|
||||||
[customerNo, username]
|
[customerNo, username]
|
||||||
);
|
);
|
||||||
logger.info("preferred_name_history table updated");
|
logger.info('preferred_name_history table updated');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === '23505') {
|
if (error.code === '23505') {
|
||||||
throw new Error('PREFERRED_NAME_ALREADY_EXISTS');
|
throw new Error('PREFERRED_NAME_ALREADY_EXISTS');
|
||||||
@@ -166,6 +166,32 @@ async function setUserName(customerNo, username) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getTncFlag(customerNo, clientType) {
|
||||||
|
let query = '';
|
||||||
|
if (clientType === 'MB') {
|
||||||
|
query = 'SELECT tnc_mobile AS tnc_flag FROM users WHERE customer_no = $1';
|
||||||
|
} else if (clientType === 'IB') {
|
||||||
|
query = 'SELECT tnc_inb AS tnc_flag FROM users WHERE customer_no = $1';
|
||||||
|
} else {
|
||||||
|
throw new Error('UNKNOWN_CLIENT_TYPE. ONLY IB AND MB ALLOWED');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.query(query, [customerNo]);
|
||||||
|
return result.rows[0]['tnc_flag'];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setTncFlag(customerNo, clientType, flag) {
|
||||||
|
let query = '';
|
||||||
|
if (clientType === 'MB') {
|
||||||
|
query = 'UPDATE users SET tnc_mobile = $1 WHERE customer_no = $2';
|
||||||
|
} else if (clientType === 'IB') {
|
||||||
|
query = 'UPDATE users SET tnc_inb = $1 WHERE customer_no = $2';
|
||||||
|
} else {
|
||||||
|
throw new Error('UNKNOWN_CLIENT_TYPE. ONLY IB AND MB ALLOWED');
|
||||||
|
}
|
||||||
|
await db.query(query, [flag, customerNo]);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validateUser,
|
validateUser,
|
||||||
findUserByCustomerNo,
|
findUserByCustomerNo,
|
||||||
@@ -180,5 +206,6 @@ module.exports = {
|
|||||||
isMigratedUser,
|
isMigratedUser,
|
||||||
CheckUserName,
|
CheckUserName,
|
||||||
setUserName,
|
setUserName,
|
||||||
|
getTncFlag,
|
||||||
|
setTncFlag,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ async function validateOutsideBank(accountNo, ifscCode, name) {
|
|||||||
|
|
||||||
async function getSingleBeneficiary(customerNo, accountNo) {
|
async function getSingleBeneficiary(customerNo, accountNo) {
|
||||||
const queryStr =
|
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';
|
'SELECT b.account_no, b.name, b.account_type, b.ifsc_code, b.created_at, 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]);
|
const result = await db.query(queryStr, [customerNo, accountNo]);
|
||||||
return result.rows[0];
|
return result.rows[0];
|
||||||
}
|
}
|
||||||
@@ -53,13 +53,14 @@ async function deleteBeneficiary(customerNo, beneficiaryAccountNo) {
|
|||||||
|
|
||||||
async function getAllBeneficiaries(customerNo) {
|
async function getAllBeneficiaries(customerNo) {
|
||||||
const queryStr =
|
const queryStr =
|
||||||
'SELECT b.account_no, b.name, b.account_type, b.ifsc_code, i.bank_name, i.branch_name FROM beneficiaries b JOIN LATERAL( SELECT * FROM ifsc_details i WHERE i.ifsc_code = b.ifsc_code LIMIT 1 ) i ON true WHERE customer_no = $1';
|
'SELECT b.account_no, b.name, b.account_type, b.ifsc_code, b.created_at, i.bank_name, i.branch_name FROM beneficiaries b JOIN LATERAL( SELECT * FROM ifsc_details i WHERE i.ifsc_code = b.ifsc_code LIMIT 1 ) i ON true WHERE customer_no = $1';
|
||||||
const result = await db.query(queryStr, [customerNo]);
|
const result = await db.query(queryStr, [customerNo]);
|
||||||
const list = result.rows.map((row) => {
|
const list = result.rows.map((row) => {
|
||||||
const details = {
|
const details = {
|
||||||
accountNo: row['account_no'],
|
accountNo: row['account_no'],
|
||||||
name: row['name'],
|
name: row['name'],
|
||||||
accountType: row['account_type'],
|
accountType: row['account_type'],
|
||||||
|
createdAt: row['created_at'],
|
||||||
};
|
};
|
||||||
if (row['ifsc_code'] === '_') {
|
if (row['ifsc_code'] === '_') {
|
||||||
details['bankName'] = 'THE KANGRA CENTRAL COOPERATIVE BANK LIMITED';
|
details['bankName'] = 'THE KANGRA CENTRAL COOPERATIVE BANK LIMITED';
|
||||||
|
|||||||
@@ -52,7 +52,13 @@ const templates = {
|
|||||||
`Dear Customer, Your OTP for updating your Preferred Name is ${otp}. It is valid for 1 minute. Do not share this OTP with anyone. -KCCB`,
|
`Dear Customer, Your OTP for updating your Preferred Name is ${otp}. It is valid for 1 minute. Do not share this OTP with anyone. -KCCB`,
|
||||||
|
|
||||||
USERNAME_SAVED: (PreferName) =>
|
USERNAME_SAVED: (PreferName) =>
|
||||||
`Dear Customer, Your Preferred Name -${PreferName} has been updated successfully. If this change was not made by you, please contact our support team immediately.`
|
`Dear Customer, Your Preferred Name -${PreferName} has been updated successfully. If this change was not made by you, please contact our support team immediately.`,
|
||||||
|
|
||||||
|
TLIMIT :(otp) =>
|
||||||
|
`Dear Customer,Please complete the transaction limit set with OTP -${otp}. -KCCB`,
|
||||||
|
|
||||||
|
TLIMIT_SET :(amount) =>
|
||||||
|
`Dear Customer,Your transaction limit for Internet Banking is set to Rs ${amount}. -KCCB`,
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = templates;
|
module.exports = templates;
|
||||||
Reference in New Issue
Block a user