refactor: Extract duplicated code patterns into shared utilities#3
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: Extract duplicated code patterns into shared utilities#3devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Backend: - asyncHandler: wraps controllers to eliminate ~25 duplicated try/catch blocks - prismaSelects: shared Prisma select constants (repoSummary, issueDetail, userSummary, commentDetail) - repoHelpers: findRepoWithAccess + verifyRepoOwner for repo lookup patterns - invalidateTokens: consolidates token decode/blacklist/clear-cookie logic - buildUpdateData: extracts partial-update building pattern - validate middleware: reusable Zod validation middleware for routes Frontend: - Consolidate duplicate UserProfile interface into types/user.ts - Consolidate duplicate getMe API call (auth.api.ts delegates to user.api.ts) - Fix implicit 'any' type on repo param in ProfilePage Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Eliminates ~380 lines of duplicated code across the backend controllers and frontend by extracting recurring patterns into reusable shared utilities.
Backend — new shared utilities:
asyncHandler(fn)500 { message: "Error in server" }. Removes ~25 identical try/catch blocks.prismaSelects.tsrepoSummarySelect,issueDetailSelect,userSummarySelect,commentDetailSelect) — previously copy-pasted 4-5x each.findRepoWithAccess(owner, repo, userId?)verifyRepoOwner(username, req, res)repo.controller.ts.invalidateTokens(access, refresh, res)buildUpdateData(fields, res)validatemiddlewareparams/query/body(available for future route-level usage).Frontend:
UserProfile/Repositoryinterfaces intotypes/user.ts(was defined separately inuseUser.tsandProfilePage.tsx).getMeAPI function —auth.api.tsnow delegates togetCurrentUserApifromuser.api.ts.anytype onrepomap parameter inProfilePage.tsx.Example — before vs after (controller pattern):
Link to Devin session: https://app.devin.ai/sessions/1f25cda24527464e95ff67b60b2e1f9b
Requested by: @amnkarn