feat: add multi-currency support to cospend payments

- Add ExchangeRate model for currency conversion tracking
- Implement currency utility functions for formatting and conversion
- Add exchange rates API endpoint with caching and fallback rates
- Update Payment and RecurringPayment models to support multiple currencies
- Enhanced payment forms with currency selection and conversion display
- Update split method selector with better currency handling
- Add currency-aware payment display and balance calculations
- Support for EUR, USD, GBP, and CHF with automatic exchange rate fetching
This commit is contained in:
2025-09-14 19:54:31 +02:00
parent b233c55ee6
commit 2b857b503b
13 changed files with 936 additions and 59 deletions
+15 -3
View File
@@ -4,8 +4,10 @@ export interface IPayment {
_id?: string;
title: string;
description?: string;
amount: number;
currency: string;
amount: number; // Always in CHF (converted if necessary)
currency: string; // Currency code (CHF if no conversion, foreign currency if converted)
originalAmount?: number; // Amount in foreign currency (only if currency != CHF)
exchangeRate?: number; // Exchange rate used for conversion (only if currency != CHF)
paidBy: string; // username/nickname of the person who paid
date: Date;
image?: string; // path to uploaded image
@@ -36,7 +38,17 @@ const PaymentSchema = new mongoose.Schema(
type: String,
required: true,
default: 'CHF',
enum: ['CHF'] // For now only CHF as requested
uppercase: true
},
originalAmount: {
type: Number,
required: false,
min: 0
},
exchangeRate: {
type: Number,
required: false,
min: 0
},
paidBy: {
type: String,