-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Description: Currency conversion logic is duplicated across multiple files, such as in routes/expenses.js (GET, POST, PUT endpoints) and potentially in other routes like routes/currency.js. This includes repeated calls to currencyService.convertCurrency and handling of originalAmount, convertedAmount, etc., leading to maintenance issues and potential bugs.
Steps to Refactor:
Create a utility module (e.g., utils/currencyHelper.js) to centralize currency conversion logic.
Define a function like convertAndFormatExpense(expense, userPreferredCurrency) that handles conversion, updates the expense object, and returns formatted data.
Refactor route handlers to use this utility instead of inline logic.
Add caching for exchange rates if not already present in currencyService to improve performance.
Update tests to cover the new utility functions.