feat: add multi-currency support to cospend payments
Some checks failed
CI / update (push) Failing after 5s
Some checks failed
CI / update (push) Failing after 5s
- 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 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
47
src/models/ExchangeRate.ts
Normal file
47
src/models/ExchangeRate.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
export interface IExchangeRate {
|
||||
_id?: string;
|
||||
fromCurrency: string; // e.g., "USD"
|
||||
toCurrency: string; // Always "CHF" for our use case
|
||||
rate: number;
|
||||
date: string; // Date in YYYY-MM-DD format
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
const ExchangeRateSchema = new mongoose.Schema(
|
||||
{
|
||||
fromCurrency: {
|
||||
type: String,
|
||||
required: true,
|
||||
uppercase: true,
|
||||
trim: true
|
||||
},
|
||||
toCurrency: {
|
||||
type: String,
|
||||
required: true,
|
||||
uppercase: true,
|
||||
trim: true,
|
||||
default: 'CHF'
|
||||
},
|
||||
rate: {
|
||||
type: Number,
|
||||
required: true,
|
||||
min: 0
|
||||
},
|
||||
date: {
|
||||
type: String,
|
||||
required: true,
|
||||
match: /^\d{4}-\d{2}-\d{2}$/
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: true
|
||||
}
|
||||
);
|
||||
|
||||
// Create compound index for efficient lookups
|
||||
ExchangeRateSchema.index({ fromCurrency: 1, toCurrency: 1, date: 1 }, { unique: true });
|
||||
|
||||
export const ExchangeRate = mongoose.model<IExchangeRate>("ExchangeRate", ExchangeRateSchema);
|
||||
Reference in New Issue
Block a user