Skip to content

Fix: Adding Comments to Partner Network Partners throws error#3977

Open
general-adhoc wants to merge 1 commit into
mainfrom
fix-network-partner-comments
Open

Fix: Adding Comments to Partner Network Partners throws error#3977
general-adhoc wants to merge 1 commit into
mainfrom
fix-network-partner-comments

Conversation

@general-adhoc
Copy link
Copy Markdown
Collaborator

@general-adhoc general-adhoc commented Jun 3, 2026

Bug: if a Program attempts to add a comment to a Partner while browsing the Partner Network, the backend rejects this comment and the UI throws an error because the Add Comment API requires program enrollment.

This functionality would be useful to Program teams evaluating partners/strategizing on outreach and should be allowed. If this behavior is intentional - fix would be to instead remove the add comment panel.

This PR updates the create partner comment API to allow this, as well as a light refactor to avoid duplicate query code in several places.

Before:

image

After:

image

Summary by CodeRabbit

  • Refactor
    • Consolidated partner reachability logic across messaging and comment features for improved code maintainability. All existing functionality remains unchanged.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 3, 2026 6:14pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a94a2a99-7a80-4495-9be0-1e2fc68ec262

📥 Commits

Reviewing files that changed from the base of the PR and between aa8b528 and e46fa41.

📒 Files selected for processing (4)
  • apps/web/app/(ee)/api/messages/route.ts
  • apps/web/lib/actions/partners/create-partner-comment.ts
  • apps/web/lib/actions/partners/message-partner.ts
  • apps/web/lib/api/partners/partner-reachable-by-program-where-input.ts

📝 Walkthrough

Walkthrough

A new helper consolidates partner reachability into partnerReachableByProgramWhereInput and replaces three inline OR reachability checks in the messages API route, create-partner-comment action, and message-partner action with calls to that helper.

Changes

Partner Reachability Logic Consolidation

Layer / File(s) Summary
Partner reachability helper definition
apps/web/lib/api/partners/partner-reachable-by-program-where-input.ts
Exports partnerReachableByProgramWhereInput(programId), returning a Prisma PartnerWhereInput that matches partners by network status (approved or trusted), program enrollment (programs.some), or existing message threads (messages.some) for the program.
Messages API partner reachability
apps/web/app/(ee)/api/messages/route.ts
Imports and spreads partnerReachableByProgramWhereInput(programId) into the prisma.partner.findMany where clause, replacing the previous inline OR-based reachability condition.
Create partner comment reachability validation
apps/web/lib/actions/partners/create-partner-comment.ts
Adds DubApiError and the helper; removes getProgramEnrollmentOrThrow enforcement and instead uses prisma.partner.findFirst with partnerReachableByProgramWhereInput(programId), throwing DubApiError({ code: "not_found", message: "Partner not found." }) when no partner is found.
Message partner action reachability check
apps/web/lib/actions/partners/message-partner.ts
Imports and spreads the reachability helper into the prisma.partner.findFirstOrThrow where clause, replacing the inline reachability OR filter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • dubinc/dub#3805: Modifies partner eligibility/lookup logic in message-partner.ts, closely related to this PR's reachability refactor.

Suggested reviewers

  • pepeladeira

Poem

🐰 A helper hops where ORs once played,
One path to find the partners made,
Spread into queries, neat and bright,
Reachability now reads just right,
I nibble code and dance tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the bug fix: enabling comments on Partner Network partners, which matches the core change of updating the create partner comment API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-network-partner-comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@general-adhoc
Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

✅ Action performed

Full review finished.

@general-adhoc general-adhoc marked this pull request as ready for review June 3, 2026 18:26
@devkiran
Copy link
Copy Markdown
Collaborator

devkiran commented Jun 4, 2026

@coderabbitai full review please

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

@devkiran Sure, I'll trigger a full review of PR #3977 right away!


🧠 Learnings used
Learnt from: steven-tey
Repo: dubinc/dub PR: 3584
File: apps/web/app/(ee)/api/admin/delete-partner-account/route.ts:120-134
Timestamp: 2026-03-14T20:01:18.394Z
Learning: In the dubinc/dub codebase, `prisma.partner.delete()` throws a Prisma error because `relationMode = "prisma"` enforces Restrict (default) on models without explicit `onDelete`: Payout, PartnerRewind, PartnerReferral, DiscountCode, and NotificationEmail all reference Partner without onDelete Cascade. The workaround is to explicitly `deleteMany` those non-cascade relations before calling `prisma.partner.delete()`.
✅ Action performed

Full review finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants