Skip to content

Code Duplication in Currency Handling #638

@Aditya8369

Description

@Aditya8369

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions