Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Oct 24, 2025

…ners.

Summary by CodeRabbit

  • New Features
    • Automatically create default links for groups missing them during campaign imports, using program domain/URL.
  • Bug Fixes
    • Improved error handling and logging for partner imports, surfacing failures with contextual details.
    • Skip campaign imports when required program domain or URL is missing to avoid incomplete processing.

@vercel
Copy link
Contributor

vercel bot commented Oct 24, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 24, 2025 5:33am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Walkthrough

Added post-processing of Promise.allSettled results to log rejected affiliate imports with email context and made partnerGroupDefaultLinks access safe. Added an early-return guard when program.domain or program.url is missing, and added default-link provisioning for groups without default links during campaign import.

Changes

Cohort / File(s) Summary
Affiliate import error handling
apps/web/lib/firstpromoter/import-partners.ts
Replace direct await of Promise.allSettled with capturing results and post-processing; import and use isRejected to log errors for rejected affiliate imports including affiliate email; make partnerGroupDefaultLinks[0] access safe via ?. and ?? (partnerGroupDefaultLinks[0]?.id ?? null).
Campaign import flow and default-link provisioning
apps/web/lib/firstpromoter/import-campaigns.ts
Add early-return guard when program.domain or program.url is missing (logs error and skips); after processing campaign batches, query for groups lacking default links and create default links using program domain/url before paging to next batch.

Sequence Diagram(s)

sequenceDiagram
    participant Importer as Import-Partners
    participant FP as FirstPromoter API
    participant DB as Database/Logger

    Note over Importer,FP: parallel affiliate imports (Promise.allSettled)
    Importer->>FP: importAffiliate(a1)
    Importer->>FP: importAffiliate(a2)
    FP-->>Importer: settled(results)
    Note right of Importer: collect results
    alt rejected results exist
        Importer->>DB: log error with affiliate email (isRejected)
    end
    Importer->>DB: continue with partner creation (use partnerGroupDefaultLinks[0]?.id ?? null)
Loading
sequenceDiagram
    participant Importer as Import-Campaigns
    participant FP as FirstPromoter API
    participant DB as Database/LinkStore

    Importer->>FP: fetchProgram(programId)
    alt program.domain or program.url missing
        Importer->>DB: log error and return (skip import)
    else
        loop per page/batch
            Importer->>FP: fetchCampaigns(page)
            FP-->>Importer: campaigns
            Importer->>DB: create/update campaigns & groups
            Note right of Importer: AFTER processing batch
            Importer->>DB: query groups missing default links
            alt groups need default links
                Importer->>DB: create default links using program.domain/url
            end
            Importer->>Importer: increment page
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

🐰 I hopped through promises, tidy and bright,
Logged every hiccup, gave errors light,
Default links planted where none used to be,
Safe chains snug as a burrow for me,
Hooray — imports now dance, error-free! 🌱✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The pull request title "Fix FirstPromoter import" references the correct component being modified and indicates that improvements were made, so it is not unrelated or misleading. However, the title is quite vague and generic—it uses the non-specific term "Fix" without clarifying what was actually fixed or improved. The changeset involves multiple distinct improvements across two files: error handling enhancements in the partners import, safer property access with optional chaining, and new default link provisioning logic in the campaigns import. The title does not convey these specifics, making it difficult for a reviewer scanning the history to understand what was changed at a glance. Consider revising the title to be more specific about the changes made, such as "Add error handling and default link provisioning to FirstPromoter imports" or "Improve FirstPromoter import error handling and campaign defaults." This would give reviewers a clearer understanding of what was changed without requiring them to inspect the full changeset details.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-firstpromoter-imports

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8d1553 and c3329a4.

📒 Files selected for processing (1)
  • apps/web/lib/firstpromoter/import-campaigns.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/lib/firstpromoter/import-campaigns.ts (1)
apps/web/lib/api/create-id.ts (1)
  • createId (66-71)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
apps/web/lib/firstpromoter/import-campaigns.ts (2)

23-28: Good defensive guard against missing required fields.

The early return prevents downstream errors when essential program fields are missing. The error message clearly identifies the program and reason for skipping.


76-96: Well-implemented default link provisioning with backfill support.

This correctly creates default links for all groups in the program that lack them, not just newly created groups. The non-null assertions on program.domain and program.url are safe due to the guard at lines 23-28. The partnerGroupDefaultLinks: { none: {} } filter is correct Prisma syntax for finding groups without related default links.

The broader scope (all groups, not just new ones) appears intentional and serves as a backfill mechanism to fix any existing groups that were previously created without default links.


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.

@steven-tey steven-tey merged commit 0becdfe into main Oct 24, 2025
4 of 6 checks passed
@steven-tey steven-tey deleted the fix-firstpromoter-imports branch October 24, 2025 05:29
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.

3 participants