-
Notifications
You must be signed in to change notification settings - Fork 34
feat(eai): pricing query to calculate total seats accurately #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe core logic for determining the available quantity of a product in the pricing query module has been revised. The updated approach now distinguishes between different purchase types, specifically handling individual purchases and those involving bulk coupons. The calculation iterates through purchases, skips invalid ones, and accurately tallies redeemed and reserved team seats based on coupon data. The total seat usage is then subtracted from the product's available quantity to yield the final available amount. No changes were made to the function signatures or public interfaces. Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
Scope: all 3 workspace projects This error happened while installing a direct dependency of /tmp/eslint/packages/config/eslint-config Packages found in the workspace: Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/epicdev-ai/src/lib/pricing-query.ts (1)
46-65
: Logic correctly handles all purchase scenariosThe categorization of purchases is well implemented, correctly handling:
- Filtering out invalid purchases
- Identifying redeemed team seats
- Calculating unredeemed seats from bulk coupons
- Counting individual purchases
Consider adding comments explaining each branch of logic for better maintainability, especially for future developers who may not be familiar with the business rules around bulk coupons.
for (const purchase of totalPurchases) { + // Skip purchases that are not valid if (purchase.status !== 'Valid') { continue } + // Count redeemed team seats (individual seats claimed from a bulk coupon) if (purchase.redeemedBulkCouponId) { redeemedTeamSeats += 1 continue } + // Calculate and reserve unclaimed seats for team purchases if (purchase.bulkCouponId && purchase.bulkCoupon) { const maxUses = purchase.bulkCoupon.maxUses const usedCount = purchase.bulkCoupon.usedCount const unredeemed = Math.max(0, maxUses - usedCount) reservedTeamSeats += unredeemed continue } + // Count individual purchases (not related to team/bulk purchases) individualPurchases += 1 }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/epicdev-ai/src/lib/pricing-query.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: format
- GitHub Check: build
🔇 Additional comments (5)
apps/epicdev-ai/src/lib/pricing-query.ts (5)
36-38
: Good addition of bulk coupon data to the queryIncluding the bulkCoupon relation in the query is essential for the new calculation logic and efficiently fetches all necessary data in a single database call.
41-45
: Well-structured variables for tracking different seat typesThe introduction of separate variables for different seat categories (individual, redeemed team, reserved team) makes the logic clear and aligns perfectly with the PR objectives of accurately tracking both claimed and unclaimed team seats.
59-59
: Good edge case handlingUsing
Math.max(0, maxUses - usedCount)
prevents negative values in case of data inconsistencies whereusedCount
might be greater thanmaxUses
.
67-67
: Clear aggregation of all seat typesThe formula correctly sums all three categories of seats to get the total count.
78-78
: Improved quantityAvailable calculationThe updated calculation now accurately subtracts the total seats (including individual purchases, redeemed team seats, and reserved team seats) from the product's available quantity, addressing the PR objective of accurately calculating total seats.
Fix quantity available calculation for team purchases
Previously, the quantity available calculation wasn't correctly accounting for team purchases and their seats. This PR:
redeemedBulkCouponId
) as 1 seat eachmaxUses - usedCount
from the couponThis ensures we have an accurate count of available spots by considering both claimed and unclaimed team seats.