implemented quick pay within bank
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { validateUser } = require('../services/auth.service');
|
||||
const authService = require('../services/auth.service');
|
||||
const { generateToken } = require('../util/jwt');
|
||||
const { logger } = require('../util/logger');
|
||||
|
||||
@@ -12,9 +12,9 @@ async function login(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await validateUser(customerNo, password);
|
||||
const user = await authService.validateUser(customerNo, password);
|
||||
if (!user) return res.status(401).json({ error: 'invalid credentials' });
|
||||
const token = generateToken(user.customer_no);
|
||||
const token = generateToken(user.customer_no, '1d');
|
||||
res.json({ token });
|
||||
} catch (err) {
|
||||
logger.error(err, 'login failed');
|
||||
@@ -22,4 +22,38 @@ async function login(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { login };
|
||||
async function tpin(req, res) {
|
||||
const customerNo = req.user;
|
||||
try {
|
||||
const user = await authService.findUserByCustomerNo(customerNo);
|
||||
if (!user) return res.status(404).json({ message: 'USER_NOT_FOUND' });
|
||||
if (!user.tpin) {
|
||||
return res.json({ tpinSet: false });
|
||||
} else {
|
||||
return res.json({ tpinSet: true });
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err, 'error occured while checking tpin');
|
||||
res.status(500).json({ error: 'something went wrong' });
|
||||
}
|
||||
}
|
||||
|
||||
async function setTpin(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_ALREADY_HAS_A_TPIN' });
|
||||
const { tpin } = req.body;
|
||||
if (!/^\d{6}$/.test(tpin))
|
||||
return res.status(400).json({ error: 'INVALID_TPIN_FORMAT' });
|
||||
authService.setTpin(customerNo, tpin);
|
||||
return res.json({ message: 'TPIN_SET' });
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return res.status(500).json({ error: 'SOMETHING_WENT_WRONG' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { login, tpin, setTpin };
|
||||
|
@@ -8,7 +8,6 @@ async function getDetails(customerNo) {
|
||||
{ params: { stcustno: customerNo } }
|
||||
);
|
||||
const details = response.data;
|
||||
logger.info(details, 'response from cbs');
|
||||
const processedDetails = details.map((acc) => ({
|
||||
...acc,
|
||||
activeAccounts: details.length,
|
||||
@@ -16,6 +15,7 @@ async function getDetails(customerNo) {
|
||||
}));
|
||||
return processedDetails;
|
||||
} catch (error) {
|
||||
logger.error('while fetching customer details', error);
|
||||
throw new Error(
|
||||
'API call failed: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
|
29
src/controllers/transfer.controller.js
Normal file
29
src/controllers/transfer.controller.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function transfer(
|
||||
fromAccountNo,
|
||||
toAccountNo,
|
||||
toAccountType,
|
||||
amount,
|
||||
narration = 'tranfer from mobile'
|
||||
) {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
'http://localhost:8689/kccb/Interbankfundtranfer',
|
||||
{
|
||||
fromAccountNo,
|
||||
toAccountNo,
|
||||
toAccountType,
|
||||
amount,
|
||||
narration,
|
||||
}
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'API call failed: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { transfer };
|
Reference in New Issue
Block a user