implemented quick pay within bank
This commit is contained in:
16
src/validators/tpin.validator.js
Normal file
16
src/validators/tpin.validator.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const authService = require('../services/auth.service');
|
||||
|
||||
const tpinValidator = async (req, res, next) => {
|
||||
const customerNo = req.user;
|
||||
const { tpin } = req.body;
|
||||
|
||||
if (!tpin) {
|
||||
return res.status(400).json({ error: 'BAD_REQUEST' });
|
||||
}
|
||||
const valid = await authService.validateTpin(customerNo, tpin);
|
||||
if (valid === null) res.status(400).json({ error: 'TPIN_NOT_SET_FOR_USER' });
|
||||
if (!valid) return res.status(401).json({ error: 'INCORRECT_TPIN' });
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = tpinValidator;
|
||||
20
src/validators/transfer.validator.js
Normal file
20
src/validators/transfer.validator.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const transferValidator = async (req, res, next) => {
|
||||
const { fromAccount, toAccount, toAccountType, amount } = req.body;
|
||||
|
||||
const accountTypes = ['SB', 'LN'];
|
||||
if (!fromAccount || fromAccount.length != 11) {
|
||||
return res.status(400).json({ error: 'INVALID_ACCOUNT_NUMBER_FORMAT' });
|
||||
}
|
||||
if (!toAccount || toAccount.length != 11) {
|
||||
return res.status(400).json({ error: 'INVALID_ACCOUNT_NUMBER_FORMAT' });
|
||||
}
|
||||
if (!accountTypes || !accountTypes.includes(toAccountType)) {
|
||||
return res.status(400).json({ error: 'INVALID_ACCOUNT_TYPE' });
|
||||
}
|
||||
if (!amount || amount <= 0) {
|
||||
return res.status(400).json({ error: 'INVALID_AMOUNT' });
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = transferValidator;
|
||||
Reference in New Issue
Block a user