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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Nov 14, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Added validation to prevent processing sales transactions with zero or negative amounts. These events are now logged and handled appropriately without further processing.

@vercel
Copy link
Contributor

vercel bot commented Nov 14, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Nov 14, 2025 9:25am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

The PR modifies apps/web/lib/api/conversions/track-sale.ts to remove unused ClickEventTB type imports and its associated local declaration, while introducing a validation guard that skips processing when sale amounts are non-positive, logging a conversion event before early exit.

Changes

Cohort / File(s) Summary
Conversion tracking validation
apps/web/lib/api/conversions/track-sale.ts
Removed ClickEventTB from type imports; removed clickData local variable; added early-exit guard in _trackSale to skip processing when amount <= 0, logging conversion event and returning null customer and sale

Sequence Diagram

sequenceDiagram
    participant Caller
    participant trackSale
    participant _trackSale
    participant Logger

    Caller->>trackSale: call trackSale(params)
    trackSale->>_trackSale: call _trackSale(params)
    
    rect rgb(240, 248, 255)
    Note over _trackSale: New validation path
    alt amount <= 0
        _trackSale->>Logger: log conversion event
        _trackSale-->>trackSale: return {eventName, customer: null, sale: null}
    else amount > 0
        Note over _trackSale: Existing currency conversion logic
        _trackSale->>_trackSale: handle currency conversion
        _trackSale-->>trackSale: return sale data
    end
    end
    
    trackSale-->>Caller: return result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Areas requiring attention:
    • Verify the new guard clause logic correctly identifies and logs non-positive amounts
    • Confirm the early-exit behavior (returning null customer and sale) aligns with downstream expectations
    • Ensure removal of ClickEventTB doesn't break any remaining references in the codebase

Possibly related PRs

Poem

🐰 ClickEventTB, now goodbye—
No more clickData cluttering by,
With guards for amounts that won't grow,
Zero sales get logged, then off they go! 🎯✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: adding a guard to skip processing when sale amounts are zero or negative.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 skip-zero-sales

📜 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 9d290d0 and 687899b.

📒 Files selected for processing (1)
  • apps/web/lib/api/conversions/track-sale.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: steven-tey
Repo: dubinc/dub PR: 2951
File: apps/web/scripts/migrations/backfill-submission-completedat.ts:16-24
Timestamp: 2025-10-09T19:50:25.662Z
Learning: Skip reviewing changes in the `scripts/` directory for the dubinc/dub repository.
📚 Learning: 2025-10-02T22:46:22.739Z
Learnt from: steven-tey
Repo: dubinc/dub PR: 2924
File: apps/web/lib/api/conversions/track-lead.ts:7-7
Timestamp: 2025-10-02T22:46:22.739Z
Learning: In apps/web/lib/api/conversions/track-lead.ts, lead events are cached in Redis for 5 minutes (keys: `leadCache:${customer.id}` and `leadCache:${customer.id}:${stringifiedEventName}`) to provide immediate data availability while Tinybird ingestion happens asynchronously. This caching pattern allows for async-only recording without breaking "wait" mode semantics.

Applied to files:

  • apps/web/lib/api/conversions/track-sale.ts
🧬 Code graph analysis (1)
apps/web/lib/api/conversions/track-sale.ts (1)
apps/web/lib/tinybird/log-conversion-events.ts (1)
  • logConversionEvent (25-28)
⏰ 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/api/conversions/track-sale.ts (2)

418-434: LGTM! Efficient early validation for non-positive amounts.

The guard correctly prevents processing zero or negative sale amounts before expensive operations like currency conversion. The placement after the leadEventData check ensures required data is available before validation, and the return format is consistent with other error cases in the file.


15-15: ClickEventTB import removal is correct cleanup.

The type was unused within the file and no external dependencies were found. The removal is safe and appropriate.


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 157c05a into main Nov 14, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the skip-zero-sales branch November 14, 2025 18:10
This was referenced Nov 24, 2025
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