Refactor handheld comment creation#439
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughComment creation logic was moved from the router into a new ListingCommentService. CommentsRepository gained existence/count helpers and a refactored create path. The router delegates to the service. Tests were extended to cover notifications, analytics, first-comment tracking, and error cases. ChangesComment Creation Service Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/server/repositories/comments.repository.ts (1)
185-194: ⚡ Quick winInconsistent error handling in
updatemethod.The new
createmethod useshandleDatabaseOperation, butupdatedoes not. For consistency, consider wrappingupdatesimilarly—it can throw P2025 if the record doesn't exist.♻️ Suggested fix
async update( id: string, data: Prisma.CommentUpdateInput, ): Promise<Prisma.CommentGetPayload<{ include: typeof CommentsRepository.includes.minimal }>> { - return this.prisma.comment.update({ - where: { id }, - data, - include: CommentsRepository.includes.minimal, - }) + return this.handleDatabaseOperation( + () => + this.prisma.comment.update({ + where: { id }, + data, + include: CommentsRepository.includes.minimal, + }), + 'Comment', + ) }Based on learnings: "Repositories should use project error helpers and consistent database operation handling"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/repositories/comments.repository.ts` around lines 185 - 194, The update method currently calls this.prisma.comment.update directly and lacks the consistent error handling used elsewhere; wrap the call inside handleDatabaseOperation to surface mapped project errors (e.g., convert Prisma P2025 to a NotFound or project-specific error) and preserve the same return type. Specifically, replace the direct call in CommentsRepository.update (signature using id: string, data: Prisma.CommentUpdateInput and include: CommentsRepository.includes.minimal) with a handleDatabaseOperation(async () => this.prisma.comment.update({...})) invocation so database errors are handled the same way as in create.Source: Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/server/services/listing-comment.service.ts`:
- Around line 54-58: The call to trackFirstComment after persisting the comment
can throw (e.g., countByUser DB error) and bubble up to the API caller; change
it to not break the request by making it fire-and-forget or catching errors:
either invoke trackFirstComment without awaiting (use void/async background) or
wrap the await in a try/catch and log the error so
emitCreatedNotification/trackCreatedComment and the returned comment are not
affected; reference the trackFirstComment function (and countByUser inside it)
and ensure any errors are logged rather than rethrown.
---
Nitpick comments:
In `@src/server/repositories/comments.repository.ts`:
- Around line 185-194: The update method currently calls
this.prisma.comment.update directly and lacks the consistent error handling used
elsewhere; wrap the call inside handleDatabaseOperation to surface mapped
project errors (e.g., convert Prisma P2025 to a NotFound or project-specific
error) and preserve the same return type. Specifically, replace the direct call
in CommentsRepository.update (signature using id: string, data:
Prisma.CommentUpdateInput and include: CommentsRepository.includes.minimal) with
a handleDatabaseOperation(async () => this.prisma.comment.update({...}))
invocation so database errors are handled the same way as in create.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 60ad175a-8939-4e60-b487-70dfe2a6713b
📒 Files selected for processing (4)
src/server/api/routers/listings/comments.test.tssrc/server/api/routers/listings/comments.tssrc/server/repositories/comments.repository.tssrc/server/services/listing-comment.service.ts
Closes #391.
Summary
Validation
Summary by CodeRabbit
Tests
Bug Fixes
Chores