mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-13 09:02:23 +00:00
Fix MonthlyTrends date parsing and add AnalyticsTransaction interface
Co-authored-by: elisiariocouto <818914+elisiariocouto@users.noreply.github.com>
This commit is contained in:
committed by
Elisiário Couto
parent
d51aa9429e
commit
0e645d9bae
@@ -48,7 +48,7 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
|
||||
const monthlyMap: { [key: string]: MonthlyData } = {};
|
||||
|
||||
transactions.forEach((transaction) => {
|
||||
const date = new Date(transaction.transaction_date);
|
||||
const date = new Date(transaction.date);
|
||||
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
|
||||
|
||||
if (!monthlyMap[monthKey]) {
|
||||
@@ -63,10 +63,10 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
|
||||
};
|
||||
}
|
||||
|
||||
if (transaction.transaction_value > 0) {
|
||||
monthlyMap[monthKey].income += transaction.transaction_value;
|
||||
if (transaction.amount > 0) {
|
||||
monthlyMap[monthKey].income += transaction.amount;
|
||||
} else {
|
||||
monthlyMap[monthKey].expenses += Math.abs(transaction.transaction_value);
|
||||
monthlyMap[monthKey].expenses += Math.abs(transaction.amount);
|
||||
}
|
||||
|
||||
monthlyMap[monthKey].net = monthlyMap[monthKey].income - monthlyMap[monthKey].expenses;
|
||||
|
||||
@@ -2,6 +2,7 @@ import axios from "axios";
|
||||
import type {
|
||||
Account,
|
||||
Transaction,
|
||||
AnalyticsTransaction,
|
||||
Balance,
|
||||
ApiResponse,
|
||||
NotificationSettings,
|
||||
@@ -168,11 +169,11 @@ export const apiClient = {
|
||||
},
|
||||
|
||||
// Get all transactions for analytics (no pagination)
|
||||
getTransactionsForAnalytics: async (days?: number): Promise<Transaction[]> => {
|
||||
getTransactionsForAnalytics: async (days?: number): Promise<AnalyticsTransaction[]> => {
|
||||
const queryParams = new URLSearchParams();
|
||||
if (days) queryParams.append("days", days.toString());
|
||||
|
||||
const response = await api.get<ApiResponse<Transaction[]>>(
|
||||
const response = await api.get<ApiResponse<AnalyticsTransaction[]>>(
|
||||
`/transactions/analytics?${queryParams.toString()}`
|
||||
);
|
||||
return response.data.data;
|
||||
|
||||
@@ -59,6 +59,17 @@ export interface RawTransactionData {
|
||||
[key: string]: unknown; // Allow additional fields
|
||||
}
|
||||
|
||||
// Type for analytics transaction data
|
||||
export interface AnalyticsTransaction {
|
||||
transaction_id: string;
|
||||
date: string;
|
||||
description: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
status: string;
|
||||
account_id: string;
|
||||
}
|
||||
|
||||
export interface Transaction {
|
||||
transaction_id: string; // NEW: stable bank-provided transaction ID
|
||||
internal_transaction_id: string | null; // OLD: unstable GoCardless ID
|
||||
|
||||
Reference in New Issue
Block a user