second commit
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const pinoHttp = require('pino-http');
|
||||
const { logger } = require('./util/logger');
|
||||
const routes = require('./routes');
|
||||
|
||||
@@ -10,7 +9,6 @@ app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// app.use(pinoHttp({ logger }));
|
||||
app.use('/api', routes);
|
||||
app.get('/health', (_, res) => res.send('server is healthy'));
|
||||
app.use((err, _req, res, _next) => {
|
||||
|
25
src/controllers/customer_details.controller.js
Normal file
25
src/controllers/customer_details.controller.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const axios = require('axios');
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
async function getDetails(customerNo) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
'http://localhost:8686/kccb/cbs/custInfo/details',
|
||||
{ params: { stcustno: customerNo } }
|
||||
);
|
||||
const details = response.data;
|
||||
logger.info(details, 'response from cbs');
|
||||
const processedDetails = details.map((acc) => ({
|
||||
...acc,
|
||||
activeAccounts: details.length,
|
||||
cifNumber: customerNo,
|
||||
}));
|
||||
return processedDetails;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'API call failed: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getDetails };
|
@@ -1,9 +0,0 @@
|
||||
const { logger } = require('../util/logger');
|
||||
const detailsObject = require('./rajatDetails_wt.json');
|
||||
|
||||
function getDetails(user) {
|
||||
logger.info(user);
|
||||
return detailsObject;
|
||||
}
|
||||
|
||||
module.exports = { getDetails };
|
@@ -1,116 +0,0 @@
|
||||
[
|
||||
{
|
||||
"stAccountNo": "50067217630",
|
||||
"stAccountType": "SA",
|
||||
"stBookingNumber": "SAVING CHQ FOR NONME",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "SAVING CHQ FOR NONME",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "933.84",
|
||||
"stCurrentBalance": "933.84",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077736845",
|
||||
"stAccountType": "TD",
|
||||
"stBookingNumber": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "10000.00",
|
||||
"stCurrentBalance": "10000.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077742351",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "DL-AGAINST DEPOSIT",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "DL-AGAINST DEPOSIT",
|
||||
"stApprovedAmount": "10000.00",
|
||||
"stAvailableBalance": "10236.00",
|
||||
"stCurrentBalance": "10236.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077756089",
|
||||
"stAccountType": "TD",
|
||||
"stBookingNumber": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "10000.00",
|
||||
"stCurrentBalance": "10000.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077842356",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "DL-AGAINST DEPOSIT",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "DL-AGAINST DEPOSIT",
|
||||
"stApprovedAmount": "10000.00",
|
||||
"stAvailableBalance": "10215.00",
|
||||
"stCurrentBalance": "10215.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50078072406",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "TL-PERSONAL",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TL-PERSONAL",
|
||||
"stApprovedAmount": "200000.00",
|
||||
"stAvailableBalance": "200825.00",
|
||||
"stCurrentBalance": "200825.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
}
|
||||
]
|
@@ -1,212 +0,0 @@
|
||||
[
|
||||
{
|
||||
"stAccountNo": "50067217630",
|
||||
"stAccountType": "SA",
|
||||
"stBookingNumber": "SAVING CHQ FOR NONME",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "SAVING CHQ FOR NONME",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "933.84",
|
||||
"stCurrentBalance": "933.84",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 612
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 10
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077736845",
|
||||
"stAccountType": "TD",
|
||||
"stBookingNumber": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "10000.00",
|
||||
"stCurrentBalance": "10000.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 10
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 662
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077742351",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "DL-AGAINST DEPOSIT",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "DL-AGAINST DEPOSIT",
|
||||
"stApprovedAmount": "10000.00",
|
||||
"stAvailableBalance": "10236.00",
|
||||
"stCurrentBalance": "10236.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 676
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 684
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077756089",
|
||||
"stAccountType": "TD",
|
||||
"stBookingNumber": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TD-LTD-NM-IND -1 Yrs",
|
||||
"stApprovedAmount": null,
|
||||
"stAvailableBalance": "10000.00",
|
||||
"stCurrentBalance": "10000.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 698
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 706
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50077842356",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "DL-AGAINST DEPOSIT",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "DL-AGAINST DEPOSIT",
|
||||
"stApprovedAmount": "10000.00",
|
||||
"stAvailableBalance": "10215.00",
|
||||
"stCurrentBalance": "10215.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 721
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 729
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
},
|
||||
{
|
||||
"stAccountNo": "50078072406",
|
||||
"stAccountType": "LN",
|
||||
"stBookingNumber": "TL-PERSONAL",
|
||||
"stBranchNo": "00002 ",
|
||||
"stCurrency": "INR",
|
||||
"stProductType": "TL-PERSONAL",
|
||||
"stApprovedAmount": "200000.00",
|
||||
"stAvailableBalance": "200825.00",
|
||||
"stCurrentBalance": "200825.00",
|
||||
"custdob": "02051982",
|
||||
"custname": "RAJAT MAHARANA",
|
||||
"mobileno": "919418573848",
|
||||
"custaddress": "DATA CENTRE KCCB CIVIL BAZAR D/SHALA DHARAMSHALA KANGRA",
|
||||
"pincode": "176215",
|
||||
"id": "AMSPM8798H",
|
||||
"transactions": [
|
||||
{
|
||||
"id": "abcd",
|
||||
"name": "John Doe",
|
||||
"date": "31-05-2025 09:05:31",
|
||||
"type": "CR",
|
||||
"amount": 10
|
||||
},
|
||||
{
|
||||
"id": "efgh",
|
||||
"name": "John Cena",
|
||||
"date": "20-05-2025 09:05:20",
|
||||
"type": "DR",
|
||||
"amount": 751
|
||||
}
|
||||
],
|
||||
"activeAccounts": 6,
|
||||
"cifNumber": "30022497139"
|
||||
}
|
||||
]
|
25
src/controllers/transactions.controller.js
Normal file
25
src/controllers/transactions.controller.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function getLastTen(accountNumber) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`http://localhost:8688/kccb/cbs/acctstmt/details`,
|
||||
{ params: { stacctno: accountNumber } }
|
||||
);
|
||||
const transactions = response.data;
|
||||
const processedTransactions = transactions.map((tx) => ({
|
||||
id: tx.stTransactionNumber,
|
||||
name: tx.stTransactionDesc,
|
||||
date: tx.stTransactionDate,
|
||||
amount: tx.stTransactionAmount.slice(0, -3),
|
||||
type: tx.stTransactionAmount.slice(-2),
|
||||
}));
|
||||
return processedTransactions;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'API call failde: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getLastTen };
|
@@ -1,8 +0,0 @@
|
||||
const express = require('express');
|
||||
const { login } = require('../controllers/auth.controller');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/login', login);
|
||||
|
||||
module.exports = router;
|
0
src/routes/auth.route.js
Normal file
0
src/routes/auth.route.js
Normal file
0
src/routes/customer_details.route.js
Normal file
0
src/routes/customer_details.route.js
Normal file
@@ -1,12 +0,0 @@
|
||||
const express = require('express');
|
||||
const customerController = require('../controllers/details');
|
||||
const auth = require('../middlewares/auth.middleware');
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/details', auth, (req, res) => {
|
||||
const user = req.user;
|
||||
const details = customerController.getDetails(user);
|
||||
return res.json(details);
|
||||
});
|
||||
|
||||
module.exports = router;
|
@@ -1,12 +1,12 @@
|
||||
const express = require('express');
|
||||
const testRoute = require('./test');
|
||||
const authRoute = require('./auth');
|
||||
const detailsRoute = require('./details');
|
||||
const authRoute = require('./auth.route');
|
||||
const detailsRoute = require('./customer_details.route');
|
||||
const transactionRoute = require('./transactions.route');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/test', testRoute);
|
||||
router.use('/auth', authRoute);
|
||||
router.use('/customer', detailsRoute);
|
||||
router.use('/transactions', transactionRoute);
|
||||
|
||||
module.exports = router;
|
||||
|
@@ -1,16 +0,0 @@
|
||||
const express = require('express');
|
||||
const db = require('../config/db');
|
||||
const { logger } = require('../util/logger');
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/ping-db', async (_req, res) => {
|
||||
try {
|
||||
const result = await db.query('SELECT NOW()');
|
||||
res.json({ time: result.rows[0].now });
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
res.status(500).json({ error: err });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
0
src/routes/transactions.route.js
Normal file
0
src/routes/transactions.route.js
Normal file
@@ -1,6 +1,5 @@
|
||||
const db = require('../config/db');
|
||||
const { comparePassword } = require('../util/hash');
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
async function findUserByCustomerNo(customerNo) {
|
||||
const result = await db.query('SELECT * FROM users WHERE customer_no = $1', [
|
||||
@@ -12,8 +11,6 @@ async function findUserByCustomerNo(customerNo) {
|
||||
async function validateUser(customerNo, password) {
|
||||
const user = await findUserByCustomerNo(customerNo);
|
||||
if (!user) return null;
|
||||
logger.info(typeof user);
|
||||
logger.info(user, 'user from database');
|
||||
const isMatch = await comparePassword(password, user.password_hash);
|
||||
return isMatch ? user : null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user