Skip to content
Snippets Groups Projects

feat: Add transaction pagination

Merged Magnus Grini requested to merge transaction-pagination into development
2 files
+ 480
326
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 15
4
@@ -12,13 +12,24 @@ const useTransactionsStore = defineStore('transactions', {
getTotalSavedWithSavingGoal: (state) => state.savingsTransactionsWithSavingGoal.reduce((acc, t) => acc + t.totalSaved, 0),
},
actions: {
async fetchTransactions(accountId) {
async fetchTransactions(accountId, page = 1) {
try {
const response = await axios.get(`/bank-accounts/${accountId}/transactions`);
this.transactions = response.data.content;
const response = await axios.get(`/bank-accounts/${accountId}/transactions`, {
params: { page: page - 1 }
});
if (response.data && Array.isArray(response.data.content)) {
this.transactions = response.data.content;
return {
totalPages: response.data.totalPages || 0,
currentPage: response.data.number + 1 // Correct for zero indexing
};
} else {
throw new Error("Invalid response structure from API");
}
} catch (error) {
console.error(error);
console.error("Error fetching transactions:", error);
this.transactions = [];
return { totalPages: 0, currentPage: 1 };
}
},
async addTransaction(transactionData, accountId) {
Loading