feat: added change tpin route

This commit is contained in:
2025-11-08 02:08:49 +05:30
parent 0164aad402
commit 55c822487b
2 changed files with 40 additions and 6 deletions

View File

@@ -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) {
const customerNo = req.user;
try {
@@ -325,6 +346,7 @@ module.exports = {
login,
tpin,
setTpin,
changeTpin,
setLoginPassword,
setTransactionPassword,
fetchUserDetails,

View File

@@ -8,12 +8,24 @@ router.post('/login', authController.login);
router.get('/user_details', authenticate, authController.fetchUserDetails);
router.get('/tpin', authenticate, authController.tpin);
router.post('/tpin', authenticate, authController.setTpin);
router.post('/change/tpin', authenticate, authController.changeTpin);
router.post('/login_password', authenticate, authController.setLoginPassword);
router.post('/transaction_password',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.post('/user_name',authenticate,authController.setUserName);
router.post(
'/transaction_password',
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.post('/user_name', authenticate, authController.setUserName);
module.exports = router;