second commit
This commit is contained in:
25
src/controllers/transactions.controller.js
Normal file
25
src/controllers/transactions.controller.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function getLastTen(accountNumber) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`http://localhost:8688/kccb/cbs/acctstmt/details`,
|
||||
{ params: { stacctno: accountNumber } }
|
||||
);
|
||||
const transactions = response.data;
|
||||
const processedTransactions = transactions.map((tx) => ({
|
||||
id: tx.stTransactionNumber,
|
||||
name: tx.stTransactionDesc,
|
||||
date: tx.stTransactionDate,
|
||||
amount: tx.stTransactionAmount.slice(0, -3),
|
||||
type: tx.stTransactionAmount.slice(-2),
|
||||
}));
|
||||
return processedTransactions;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'API call failde: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getLastTen };
|
Reference in New Issue
Block a user