second commit

This commit is contained in:
2025-06-17 12:13:26 +05:30
parent c350c591f6
commit d813784305
16 changed files with 186 additions and 382 deletions

131
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.9.0",
"bcrypt": "^6.0.0", "bcrypt": "^6.0.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.5.0", "dotenv": "^16.5.0",
@@ -397,6 +398,12 @@
"dev": true, "dev": true,
"license": "Python-2.0" "license": "Python-2.0"
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/atomic-sleep": { "node_modules/atomic-sleep": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz",
@@ -406,6 +413,17 @@
"node": ">=8.0.0" "node": ">=8.0.0"
} }
}, },
"node_modules/axios": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -653,6 +671,18 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/commander": { "node_modules/commander": {
"version": "14.0.0", "version": "14.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz",
@@ -771,6 +801,15 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/depd": { "node_modules/depd": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -890,6 +929,21 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": { "node_modules/escape-html": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
@@ -1301,6 +1355,62 @@
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
}, },
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/form-data/node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/form-data/node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/forwarded": { "node_modules/forwarded": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -1462,6 +1572,21 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"license": "MIT",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": { "node_modules/hasown": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
@@ -2668,6 +2793,12 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/pstree.remy": { "node_modules/pstree.remy": {
"version": "1.1.8", "version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",

View File

@@ -13,6 +13,7 @@
"license": "ISC", "license": "ISC",
"description": "", "description": "",
"dependencies": { "dependencies": {
"axios": "^1.9.0",
"bcrypt": "^6.0.0", "bcrypt": "^6.0.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.5.0", "dotenv": "^16.5.0",

View File

@@ -1,6 +1,5 @@
const express = require('express'); const express = require('express');
const cors = require('cors'); const cors = require('cors');
const pinoHttp = require('pino-http');
const { logger } = require('./util/logger'); const { logger } = require('./util/logger');
const routes = require('./routes'); const routes = require('./routes');
@@ -10,7 +9,6 @@ app.use(cors());
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
// app.use(pinoHttp({ logger }));
app.use('/api', routes); app.use('/api', routes);
app.get('/health', (_, res) => res.send('server is healthy')); app.get('/health', (_, res) => res.send('server is healthy'));
app.use((err, _req, res, _next) => { app.use((err, _req, res, _next) => {

View 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 };

View File

@@ -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 };

View File

@@ -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"
}
]

View File

@@ -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"
}
]

View 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 };

View File

@@ -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
View File

View File

View 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;

View File

@@ -1,12 +1,12 @@
const express = require('express'); const express = require('express');
const testRoute = require('./test'); const authRoute = require('./auth.route');
const authRoute = require('./auth'); const detailsRoute = require('./customer_details.route');
const detailsRoute = require('./details'); const transactionRoute = require('./transactions.route');
const router = express.Router(); const router = express.Router();
router.use('/test', testRoute);
router.use('/auth', authRoute); router.use('/auth', authRoute);
router.use('/customer', detailsRoute); router.use('/customer', detailsRoute);
router.use('/transactions', transactionRoute);
module.exports = router; module.exports = router;

View File

@@ -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;

View File

View File

@@ -1,6 +1,5 @@
const db = require('../config/db'); const db = require('../config/db');
const { comparePassword } = require('../util/hash'); const { comparePassword } = require('../util/hash');
const { logger } = require('../util/logger');
async function findUserByCustomerNo(customerNo) { async function findUserByCustomerNo(customerNo) {
const result = await db.query('SELECT * FROM users WHERE customer_no = $1', [ 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) { async function validateUser(customerNo, password) {
const user = await findUserByCustomerNo(customerNo); const user = await findUserByCustomerNo(customerNo);
if (!user) return null; if (!user) return null;
logger.info(typeof user);
logger.info(user, 'user from database');
const isMatch = await comparePassword(password, user.password_hash); const isMatch = await comparePassword(password, user.password_hash);
return isMatch ? user : null; return isMatch ? user : null;
} }