added beneficiary routes
This commit is contained in:
25
src/controllers/beneficiary.controller.js
Normal file
25
src/controllers/beneficiary.controller.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { logger } = require('../util/logger');
|
||||
const beneficiaryService = require('../services/beneficiary.service');
|
||||
|
||||
async function validateWithinBank(req, res) {
|
||||
const { accountNumber } = req.query;
|
||||
|
||||
if (!accountNumber) {
|
||||
res.status(400).json({
|
||||
error: 'account number is required',
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const beneficiaryName =
|
||||
await beneficiaryService.validateWithinBank(accountNumber);
|
||||
if (!beneficiaryName)
|
||||
return res.status(401).json({ error: 'invalid account number' });
|
||||
return res.json({ name: beneficiaryName });
|
||||
} catch (err) {
|
||||
logger.error(err, 'beneficiary validation within bank failed');
|
||||
res.status(500).json({ error: 'invalid account number' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { validateWithinBank };
|
Reference in New Issue
Block a user