feat: Feature 1.5 — Bet Submission with 3 methods + performance tracking
Three submission methods: - POST /api/bets/quickslip — structured bet entry - POST /api/bets/screenshot — stub OCR with confirm flow - POST /api/bets/sync — coming soon stub Full bet lifecycle: - PATCH /api/bets/:id/settle — settle with outcome, recalculates performance - GET /api/bets — list with status/book/pagination filters - GET /api/bets/performance — ROI, win rate, profit (weekly/monthly/all_time) Payout calculator handles straight bets (American odds) and parlays (multiplied leg payouts). Performance service recalculates on each settlement and upserts into performance table. 33 new tests, 221 total (194 Node.js + 27 Python), all passing. All backend features for Phase 1 + Phase 2 now complete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
function calculateStraightPayout(amount, odds) {
|
||||
if (odds < 0) {
|
||||
return amount + (amount / (Math.abs(odds) / 100));
|
||||
}
|
||||
return amount + (amount * (odds / 100));
|
||||
}
|
||||
|
||||
function calculateParlayPayout(amount, legsOdds) {
|
||||
let multiplier = 1;
|
||||
for (const odds of legsOdds) {
|
||||
if (odds < 0) {
|
||||
multiplier *= 1 + (100 / Math.abs(odds));
|
||||
} else {
|
||||
multiplier *= 1 + (odds / 100);
|
||||
}
|
||||
}
|
||||
return amount * multiplier;
|
||||
}
|
||||
|
||||
function calculatePayout(amount, betType, legsOdds) {
|
||||
if (!legsOdds || legsOdds.length === 0) return amount;
|
||||
|
||||
if (betType === 'straight' || legsOdds.length === 1) {
|
||||
return Math.round(calculateStraightPayout(amount, legsOdds[0]) * 100) / 100;
|
||||
}
|
||||
|
||||
// parlay, teaser, round_robin all use multiplied odds for MVP
|
||||
return Math.round(calculateParlayPayout(amount, legsOdds) * 100) / 100;
|
||||
}
|
||||
|
||||
module.exports = { calculatePayout, calculateStraightPayout, calculateParlayPayout };
|
||||
Reference in New Issue
Block a user