mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-14 16:02:25 +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 } = {};
|
const monthlyMap: { [key: string]: MonthlyData } = {};
|
||||||
|
|
||||||
transactions.forEach((transaction) => {
|
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')}`;
|
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
|
||||||
|
|
||||||
if (!monthlyMap[monthKey]) {
|
if (!monthlyMap[monthKey]) {
|
||||||
@@ -63,10 +63,10 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transaction.transaction_value > 0) {
|
if (transaction.amount > 0) {
|
||||||
monthlyMap[monthKey].income += transaction.transaction_value;
|
monthlyMap[monthKey].income += transaction.amount;
|
||||||
} else {
|
} 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;
|
monthlyMap[monthKey].net = monthlyMap[monthKey].income - monthlyMap[monthKey].expenses;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import axios from "axios";
|
|||||||
import type {
|
import type {
|
||||||
Account,
|
Account,
|
||||||
Transaction,
|
Transaction,
|
||||||
|
AnalyticsTransaction,
|
||||||
Balance,
|
Balance,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
NotificationSettings,
|
NotificationSettings,
|
||||||
@@ -168,11 +169,11 @@ export const apiClient = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Get all transactions for analytics (no pagination)
|
// Get all transactions for analytics (no pagination)
|
||||||
getTransactionsForAnalytics: async (days?: number): Promise<Transaction[]> => {
|
getTransactionsForAnalytics: async (days?: number): Promise<AnalyticsTransaction[]> => {
|
||||||
const queryParams = new URLSearchParams();
|
const queryParams = new URLSearchParams();
|
||||||
if (days) queryParams.append("days", days.toString());
|
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()}`
|
`/transactions/analytics?${queryParams.toString()}`
|
||||||
);
|
);
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
|
|||||||
@@ -59,6 +59,17 @@ export interface RawTransactionData {
|
|||||||
[key: string]: unknown; // Allow additional fields
|
[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 {
|
export interface Transaction {
|
||||||
transaction_id: string; // NEW: stable bank-provided transaction ID
|
transaction_id: string; // NEW: stable bank-provided transaction ID
|
||||||
internal_transaction_id: string | null; // OLD: unstable GoCardless ID
|
internal_transaction_id: string | null; // OLD: unstable GoCardless ID
|
||||||
|
|||||||
Reference in New Issue
Block a user