From d813784305de624188b92b4a6190e99798371d1a Mon Sep 17 00:00:00 2001 From: asif Date: Tue, 17 Jun 2025 12:13:26 +0530 Subject: [PATCH] second commit --- package-lock.json | 131 +++++++++++ package.json | 1 + src/app.js | 2 - .../customer_details.controller.js | 25 +++ src/controllers/details.js | 9 - src/controllers/rajatDetails_nt.json | 116 ---------- src/controllers/rajatDetails_wt.json | 212 ------------------ src/controllers/transactions.controller.js | 25 +++ src/routes/auth.js | 8 - src/routes/auth.route.js | 0 src/routes/customer_details.route.js | 0 src/routes/details.js | 12 - src/routes/index.js | 8 +- src/routes/test.js | 16 -- src/routes/transactions.route.js | 0 src/services/auth.service.js | 3 - 16 files changed, 186 insertions(+), 382 deletions(-) create mode 100644 src/controllers/customer_details.controller.js delete mode 100644 src/controllers/details.js delete mode 100644 src/controllers/rajatDetails_nt.json delete mode 100644 src/controllers/rajatDetails_wt.json create mode 100644 src/controllers/transactions.controller.js delete mode 100644 src/routes/auth.js create mode 100644 src/routes/auth.route.js create mode 100644 src/routes/customer_details.route.js delete mode 100644 src/routes/details.js delete mode 100644 src/routes/test.js create mode 100644 src/routes/transactions.route.js diff --git a/package-lock.json b/package-lock.json index 1bd5be3..e1484f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "axios": "^1.9.0", "bcrypt": "^6.0.0", "cors": "^2.8.5", "dotenv": "^16.5.0", @@ -397,6 +398,12 @@ "dev": true, "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": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", @@ -406,6 +413,17 @@ "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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -653,6 +671,18 @@ "dev": true, "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": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz", @@ -771,6 +801,15 @@ "dev": true, "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": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -890,6 +929,21 @@ "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": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -1301,6 +1355,62 @@ "dev": true, "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": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -1462,6 +1572,21 @@ "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": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -2668,6 +2793,12 @@ "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": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", diff --git a/package.json b/package.json index 20f93ee..a86210a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "license": "ISC", "description": "", "dependencies": { + "axios": "^1.9.0", "bcrypt": "^6.0.0", "cors": "^2.8.5", "dotenv": "^16.5.0", diff --git a/src/app.js b/src/app.js index adacfa2..3c86b46 100644 --- a/src/app.js +++ b/src/app.js @@ -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) => { diff --git a/src/controllers/customer_details.controller.js b/src/controllers/customer_details.controller.js new file mode 100644 index 0000000..00759a3 --- /dev/null +++ b/src/controllers/customer_details.controller.js @@ -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 }; diff --git a/src/controllers/details.js b/src/controllers/details.js deleted file mode 100644 index b50a599..0000000 --- a/src/controllers/details.js +++ /dev/null @@ -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 }; diff --git a/src/controllers/rajatDetails_nt.json b/src/controllers/rajatDetails_nt.json deleted file mode 100644 index 5a0bff7..0000000 --- a/src/controllers/rajatDetails_nt.json +++ /dev/null @@ -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" - } -] diff --git a/src/controllers/rajatDetails_wt.json b/src/controllers/rajatDetails_wt.json deleted file mode 100644 index d1dccb6..0000000 --- a/src/controllers/rajatDetails_wt.json +++ /dev/null @@ -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" - } -] diff --git a/src/controllers/transactions.controller.js b/src/controllers/transactions.controller.js new file mode 100644 index 0000000..47a4f81 --- /dev/null +++ b/src/controllers/transactions.controller.js @@ -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 }; diff --git a/src/routes/auth.js b/src/routes/auth.js deleted file mode 100644 index f968719..0000000 --- a/src/routes/auth.js +++ /dev/null @@ -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; diff --git a/src/routes/auth.route.js b/src/routes/auth.route.js new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/customer_details.route.js b/src/routes/customer_details.route.js new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/details.js b/src/routes/details.js deleted file mode 100644 index fff22dd..0000000 --- a/src/routes/details.js +++ /dev/null @@ -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; diff --git a/src/routes/index.js b/src/routes/index.js index b4ca071..dd05447 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -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; diff --git a/src/routes/test.js b/src/routes/test.js deleted file mode 100644 index c4e0b25..0000000 --- a/src/routes/test.js +++ /dev/null @@ -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; diff --git a/src/routes/transactions.route.js b/src/routes/transactions.route.js new file mode 100644 index 0000000..e69de29 diff --git a/src/services/auth.service.js b/src/services/auth.service.js index 07682e6..be03090 100644 --- a/src/services/auth.service.js +++ b/src/services/auth.service.js @@ -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; }