48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
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)
|
|
);
|
|
}
|
|
}
|
|
async function getFiltered(accountNumber, fromDate, toDate) {
|
|
try {
|
|
const response = await axios.get(
|
|
`http://localhost:8688/kccb/cbs/montlyacctstmt/details`,
|
|
{
|
|
params: { stacctno: accountNumber, fromdate: fromDate, todate: toDate },
|
|
}
|
|
);
|
|
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, getFiltered };
|