Add DB-backed Promo Manager: admin UI, eligibility & claim workflow - #83
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis pull request refactors the promo management system from environment-driven, in-memory defaults to a persistent, database-backed subsystem. It introduces promo status and eligibility constants, adds helper functions for promo operations, restructures admin commands for streamlined management, implements persistent storage via promo-manager-db.json, and reworks eligibility checking and claim workflows. Changes
Sequence Diagram(s)sequenceDiagram
actor User
actor Admin
participant System as Promo System
participant DB as promoManagerDb
Admin->>System: admin_pm_create_name("Bonus Promo")
Admin->>System: admin_pm_create_requirement(NEW_USER_ONLY)
Admin->>System: admin_pm_create_claim_limit(100)
System->>DB: savePromoManagerDb()
DB-->>System: ✓ Saved
User->>System: getActivePromoCodeForUser()
System->>System: listActivePromos()
System->>System: evaluatePromoEligibility(user, promo)
alt Eligible
System->>System: renderPromoForUser(promo)
System-->>User: Promo displayed
else Ineligible
System-->>User: Not eligible
end
User->>System: redeemPromo(promoId)
System->>System: evaluatePromoEligibility(user, promo)
alt Verified
System->>DB: Create claim (promo_id, user_id, status=PENDING)
DB-->>System: Claim created
System->>DB: savePromoManagerDb()
System-->>User: Claim submitted
else Failed
System->>DB: Record eligibility failure
System-->>User: Claim rejected
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches🧪 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 |
Motivation
.envor code.Description
data/promo-manager-db.jsonwithpromoManagerStore(promos, claims, eligibilityFailures) and helper functionssavePromoManagerDb()/loadPromoManagerDb(); wire persistence intopersistRuntimeState()and startup loader.normalizePromoManagerPromo,listActivePromos,getPromoById,countPromoClaims,hasRedeemedAnyPromo,getRollingWagerForUser, andevaluatePromoEligibilityto evaluate new/existing/wager requirements and cooldowns./promonow opens the Promo Menu,menu_claim_bonuslists only promos the user is eligible for, promo preview/claim handlers (promo_open_<id>,promo_claim_<id>) were added, and user claim records are stored inpromoManagerStore.claims(auto-approve vspending_approval).🎛 Promo Managerand keyboard (adminPromoToolsKeyboard) with actions to open manager,admin_pm_create(9-step guided creation),admin_pm_edit,admin_pm_pause_toggle,admin_pm_delete,admin_pm_stats,admin_pm_preview, andadmin_pm_queue(approval queue). Legacy promo code manager and broadcast paths now point admins to the Promo Manager./pmapprove <claim_id>and/pmdeny <claim_id> <reason>which approve/deny pending claims and notify users.PROMO_AUDIENCE,PROMO_REQUIREMENT_TYPE,promoCodeStore) while removing reliance onPROMO_*env vars for runtime promo behavior;promoStorenow only holds bonusRule/bugreports/logs.Testing
npm run check; it completed successfully after fixes to inserted templates.npm test(node test files undertest/*.test.js); all tests passed (33/33).promo-manager-db.jsonon startup, persistence calls added topersistRuntimeState(), and menus/commands wired and exercised by unit tests.Codex Task
Summary by CodeRabbit