feat: added change tpin route
This commit is contained in:
@@ -169,6 +169,27 @@ async function setTpin(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
if(oldTpin !== user.tpin)
|
||||||
|
return res.status(400).json({ error: 'TPIN_DOESNT_MATCH' });
|
||||||
|
|
||||||
|
if (!/^\d{6}$/.test(newTpin))
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function setLoginPassword(req, res) {
|
async function setLoginPassword(req, res) {
|
||||||
const customerNo = req.user;
|
const customerNo = req.user;
|
||||||
try {
|
try {
|
||||||
@@ -325,6 +346,7 @@ module.exports = {
|
|||||||
login,
|
login,
|
||||||
tpin,
|
tpin,
|
||||||
setTpin,
|
setTpin,
|
||||||
|
changeTpin,
|
||||||
setLoginPassword,
|
setLoginPassword,
|
||||||
setTransactionPassword,
|
setTransactionPassword,
|
||||||
fetchUserDetails,
|
fetchUserDetails,
|
||||||
|
|||||||
@@ -8,12 +8,24 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user