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>
47 lines
1009 B
TypeScript
47 lines
1009 B
TypeScript
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); |