Implement role management and updateRequest support for isApproved#72
Conversation
…ed role management functionality
📝 WalkthroughWalkthroughThe PR replaces the boolean ChangesRole Enum Migration and updateMemberRole Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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)
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.
🧹 Nitpick comments (1)
src/services/member.service.ts (1)
169-172: ⚡ Quick winMissing target member existence check before update.
If
memberIddoes not exist, Prisma throws aPrismaClientKnownRequestErrorwith codeP2025rather than a user-friendly 404. Consider fetching the target member first or catching the Prisma error to return a clearer response.♻️ Proposed fix
+ // Verify target member exists + const target = await prisma.member.findUnique({ + where: { id: memberId }, + select: { id: true }, + }); + + if (!target) { + throw new ApiError("Member not found", 404); + } + return await prisma.member.update({ where: { id: memberId }, data: { role: newRole }, });🤖 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/services/member.service.ts` around lines 169 - 172, The prisma.member.update() call in the member update method does not verify that the target member exists before attempting the update, which results in an unhelpful Prisma error when the member is not found. Either fetch the member first using prisma.member.findUnique() to verify it exists and return a proper 404 error if not found, or wrap the update call in a try-catch block that catches PrismaClientKnownRequestError with code P2025 and returns a user-friendly 404 response with a clear error message.
🤖 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.
Nitpick comments:
In `@src/services/member.service.ts`:
- Around line 169-172: The prisma.member.update() call in the member update
method does not verify that the target member exists before attempting the
update, which results in an unhelpful Prisma error when the member is not found.
Either fetch the member first using prisma.member.findUnique() to verify it
exists and return a proper 404 error if not found, or wrap the update call in a
try-catch block that catches PrismaClientKnownRequestError with code P2025 and
returns a user-friendly 404 response with a clear error message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fd6230cd-32f1-4d04-ac2a-9190b460e28f
📒 Files selected for processing (9)
prisma/migrations/20260616181835_new_role_added/migration.sqlprisma/schema.prismasrc/controllers/member.controller.tssrc/routes/members.tssrc/services/member.service.tssrc/services/site-content.service.tstests/Member.test.tstests/SiteContent.test.tstsconfig.json
Summary by CodeRabbit
New Features
Updates