Files
vyndr/src/routes/parlay.js
T
builtbykev f0c8b4f29b Session 32: Grades pipeline + NFL/NHL wiring + rate limiting + audit cleanup (1718 tests)
- gradeSlateService writes grades:{sport} cache (closes content pipeline →
  dataLevel full); fire-and-forget from oddsService.recordDownstream, gated
  by shouldGradeSlate (off in test, GRADE_SLATE_ON_FETCH override)
- NFL/NHL wired: oddsService SPORT_KEYS/SPORT_MARKETS (correct the-odds-api
  keys americanfootball_nfl/icehockey_nhl), proplineAdapter MARKETS, NHL
  MARKET_MAP keys to avoid silent-zero
- rate limiting mounted on 8 public cached routers (odds/parlay 30/min,
  rest 60/min)
- jsonlLogger writes to temp under test (no more dirtied tracked artifact);
  5MB pipeline test given 20s timeout

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 18:21:32 -04:00

50 lines
1.6 KiB
JavaScript

'use strict';
/**
* /api/parlay (Session 28)
*
* Builder-side parlay math — combined odds, grade, and correlation flags
* for a set of user-selected legs. Distinct from the existing parlay
* GRADING path (parlayGrader); this is the lightweight, zero-credit
* combination used by the live parlay builder.
*
* POST /api/parlay/calculate { legs: [...] } → combined analysis
* POST /api/parlay/suggestions { props, legs?, max? } → suggested combos
*/
const express = require('express');
const parlayService = require('../services/parlayService');
const { createRateLimit } = require('../middleware/rateLimit');
const router = express.Router();
// Session 32 — public throttle. Parlay math is computation-heavy → 30/min.
router.use(createRateLimit({ windowMs: 60_000, max: 30 }));
const MISSION_HEADER = { 'X-VYNDR-Mission': 'Catch the legs that fight each other' };
router.post('/calculate', (req, res) => {
try {
const legs = req.body?.legs;
const result = parlayService.calculateParlay(legs);
return res.set(MISSION_HEADER).json(result);
} catch (err) {
const status = err.statusCode || 400;
return res.status(status).set(MISSION_HEADER).json({ error: err.message });
}
});
router.post('/suggestions', (req, res) => {
try {
const { props, legs, max } = req.body || {};
const suggestions = parlayService.suggestParlays(props || [], {
legs: Number(legs) || 3,
max: Number(max) || 3,
});
return res.set(MISSION_HEADER).json({ suggestions });
} catch (err) {
return res.status(400).set(MISSION_HEADER).json({ error: err.message });
}
});
module.exports = router;