Skip to content

Large and Complex Route Files (e.g., routes/expenses.js) #636

@Aditya8369

Description

@Aditya8369

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).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions