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