Draft
Refactor duplicated code into centralized utilities#22
Conversation
Co-authored-by: Xsidz <146343711+Xsidz@users.noreply.github.com>
Co-authored-by: Xsidz <146343711+Xsidz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicated code to enhance maintainability
Refactor duplicated code into centralized utilities
Dec 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eliminated duplicated validation, error handling, and state management patterns across backend controllers and frontend stores.
Backend
Created utilities:
passwordUtils.js- Centralized password regex, validation message, hashing, and comparisonerrorHandler.js- Standardized HTTP error responses (400/403/404/500)Refactored: 5 controllers, 1 model
Before:
After:
Frontend
Created
storeHelpers.js:handleStoreError()- Extract error messages from API responsesapplyFilters()- Generic array filtering for search/filter stateRefactored: 4 Zustand stores
Replaced 15+ instances of
error.response?.data?.message || 'default message'and collapsed duplicate filter logic in userStore and storeStore into single reusable function.Stats
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.