Send rejection emails when bulk rejecting partner applications - #3678
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughFetches program details, preserves audit logging and fraud resolution in a post-transaction background task, then conditionally sends batch rejection emails to partners with emails using program.name and program.supportEmail; email errors are caught and logged without affecting earlier background work. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Action as ServerAction
participant DB
participant Audit as Audit/Fraud
participant Email as EmailService
Client->>Action: invoke bulkRejectPartnerApplications
Action->>DB: transactional updates (reject applications)
Action->>Action: waitUntil(async IIFE)
activate Action
Action->>Audit: recordAuditLog(...)
Action->>Audit: resolveFraudGroups(...)
Audit-->>Action: settled
Action->>DB: fetch program (name, slug, supportEmail)
Action->>Email: sendBatchEmail(recipients, renderedTemplate)
Email-->>Action: success/failure (errors caught & logged)
Action-->>Client: respond (transaction completed)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 (2)
apps/web/lib/actions/partners/bulk-reject-partner-applications.ts (2)
160-165: Consider including partner count in error log for debugging.Adding the count of partners attempted would help diagnose partial failures.
🔧 Enhanced error logging
} catch (error) { console.error("Failed to send bulk rejection emails", { error, programId, + partnerCount: partnersWithEmail.length, }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/lib/actions/partners/bulk-reject-partner-applications.ts` around lines 160 - 165, The catch block in bulk-reject-partner-applications.ts logs failure to send bulk rejection emails but omits how many partners were involved; update the catch in the try/catch that currently calls console.error("Failed to send bulk rejection emails", { error, programId }) to include the partner count (e.g., compute partnerCount from the variable used to iterate/reject partners such as partners.length or partnerIds.length, guarding for undefined) and include partnerCount in the logged object so the log becomes something like console.error(..., { error, programId, partnerCount }) to aid debugging of partial failures.
132-159: Consider chunking for large batch email sends.If many partners are rejected at once, the batch email call may exceed Resend's API limit of 100 emails per batch. Without chunking, a large rejection batch could fail or be partially processed.
♻️ Proposed chunking implementation
const partnersWithEmail = programEnrollments .filter(({ partner }) => partner.email) .map(({ partner }) => partner); if (partnersWithEmail.length > 0) { try { - await sendBatchEmail( - partnersWithEmail.map((partner) => ({ + const BATCH_SIZE = 100; + const emailPayloads = partnersWithEmail.map((partner) => ({ to: partner.email!, subject: `Your application to ${program.name} was not approved`, variant: "notifications" as const, replyTo: program.supportEmail || "noreply", react: PartnerApplicationRejected({ partner: { name: partner.name ?? "there", email: partner.email!, }, program: { name: program.name, slug: program.slug, supportEmail: program.supportEmail ?? undefined, }, rejectionReason: undefined, additionalNotes: undefined, canReapplyImmediately: false, }), - })), - ); + })); + + for (let i = 0; i < emailPayloads.length; i += BATCH_SIZE) { + await sendBatchEmail(emailPayloads.slice(i, i + BATCH_SIZE)); + } } catch (error) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/lib/actions/partners/bulk-reject-partner-applications.ts` around lines 132 - 159, The current sendBatchEmail call can exceed Resend's 100-recipient limit when partnersWithEmail (derived from programEnrollments) is large; split partnersWithEmail into chunks of at most 100 and call sendBatchEmail for each chunk sequentially (or in controlled parallelism), mapping each chunk to the same payload shape used now; update the try/catch to handle per-chunk failures (e.g., log which chunk failed or rethrow after aggregating errors). Ensure you modify the area around partnersWithEmail and the sendBatchEmail invocation so the batching logic slices partnersWithEmail into arrays of size <=100 before mapping and sending.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/lib/actions/partners/bulk-reject-partner-applications.ts`:
- Around line 160-165: The catch block in bulk-reject-partner-applications.ts
logs failure to send bulk rejection emails but omits how many partners were
involved; update the catch in the try/catch that currently calls
console.error("Failed to send bulk rejection emails", { error, programId }) to
include the partner count (e.g., compute partnerCount from the variable used to
iterate/reject partners such as partners.length or partnerIds.length, guarding
for undefined) and include partnerCount in the logged object so the log becomes
something like console.error(..., { error, programId, partnerCount }) to aid
debugging of partial failures.
- Around line 132-159: The current sendBatchEmail call can exceed Resend's
100-recipient limit when partnersWithEmail (derived from programEnrollments) is
large; split partnersWithEmail into chunks of at most 100 and call
sendBatchEmail for each chunk sequentially (or in controlled parallelism),
mapping each chunk to the same payload shape used now; update the try/catch to
handle per-chunk failures (e.g., log which chunk failed or rethrow after
aggregating errors). Ensure you modify the area around partnersWithEmail and the
sendBatchEmail invocation so the batching logic slices partnersWithEmail into
arrays of size <=100 before mapping and sending.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bac0b71e-b795-49d6-92de-6db99e738fa3
📒 Files selected for processing (1)
apps/web/lib/actions/partners/bulk-reject-partner-applications.ts
|
@coderabbitai full review please |
|
🧠 Learnings used✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/lib/actions/partners/bulk-reject-partner-applications.ts (1)
136-159: Consider adding error handling for email sending failures.The PR description mentions "error handling and logging for email sending failures," but the
sendBatchEmailcall is not wrapped in a try-catch. If the email sending fails, the error will propagate silently in thewaitUntilcontext without any explicit logging.♻️ Suggested improvement with error handling
if (partnersWithEmail.length > 0) { + try { await sendBatchEmail( partnersWithEmail.map((partner) => ({ to: partner.email!, subject: `Your application to ${program.name} was not approved`, variant: "notifications", replyTo: program.supportEmail || "noreply", react: PartnerApplicationRejected({ partner: { name: partner.name ?? "there", email: partner.email!, }, program: { name: program.name, slug: program.slug, supportEmail: program.supportEmail ?? undefined, }, rejectionReason: undefined, additionalNotes: undefined, canReapplyImmediately: false, }), })), ); + } catch (error) { + console.error( + "Failed to send bulk rejection emails:", + error, + ); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/lib/actions/partners/bulk-reject-partner-applications.ts` around lines 136 - 159, The sendBatchEmail invocation for partnersWithEmail should be wrapped in a try-catch so email sending failures are caught and logged instead of propagating from the waitUntil context; update the block around sendBatchEmail (the call that maps partnersWithEmail to PartnerApplicationRejected payloads) to catch errors, call your logger (or processLogger) with context including program.slug and number of recipients, and decide whether to rethrow or return a failure result — at minimum log the error and continue so the surrounding bulk-reject flow can handle partial failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/lib/actions/partners/bulk-reject-partner-applications.ts`:
- Around line 136-159: The sendBatchEmail invocation for partnersWithEmail
should be wrapped in a try-catch so email sending failures are caught and logged
instead of propagating from the waitUntil context; update the block around
sendBatchEmail (the call that maps partnersWithEmail to
PartnerApplicationRejected payloads) to catch errors, call your logger (or
processLogger) with context including program.slug and number of recipients, and
decide whether to rethrow or return a failure result — at minimum log the error
and continue so the surrounding bulk-reject flow can handle partial failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 71aa2568-7230-4799-9be0-1a49aba83494
📒 Files selected for processing (1)
apps/web/lib/actions/partners/bulk-reject-partner-applications.ts
Added email notification functionality to bulk partner application rejection
Summary by CodeRabbit
New Features
Improvements