-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Description: The routes/expenses.js file is over 300 lines long with complex logic in endpoints like POST and PUT, including auto-categorization, currency conversion, approval workflows, and real-time updates. This violates the Single Responsibility Principle, making the code hard to maintain, test, and debug. Similar issues may exist in other route files like routes/groups.js or routes/splits.js.
Steps to Refactor:
Extract business logic into dedicated service functions (e.g., move currency conversion to a currencyUtils.js file).
Create middleware for common validations (e.g., expense schema validation and currency checks).
Break down the POST endpoint into smaller, reusable functions (e.g., handleAutoCategorization, handleCurrencyConversion, handleApprovalSubmission).
Use async/await consistently and add error handling wrappers.
Split the file into multiple files if it grows too large (e.g., expenseCreation.js, expenseRetrieval.js).