deckhearth/pages/api/cards/[id]/price-history.js
Randall Stillwell d0468015eb
Some checks failed
CI / Lint (pull_request) Has been cancelled
CI / Schema map up to date (pull_request) Has been cancelled
CI / Forbidden patterns (9 checks) (pull_request) Has been cancelled
CI / Migrations apply (node-pg-migrate) (pull_request) Has been cancelled
Visual diff / Should run? (pull_request) Has been cancelled
CI / Unit tests (vitest) (pull_request) Has been cancelled
Convoy metrics gate / Require role-event telemetry on convoy PRs (pull_request) Has been cancelled
PR Health rollup / Aggregate gate status (pull_request) Has been cancelled
Preview smoke / Should run? (pull_request) Has been cancelled
Preview smoke / Playwright smoke (pull_request) Has been cancelled
Visual diff / Screenshot diff (pull_request) Has been cancelled
feat(pricing): convoy for online prices and local stores
Add pricing schema, free API integrations (MTG bulk, TCGdex, Foolio),
valuation and sort-by-price, card detail pricing UI, and nearby store
discovery via home zip and OSM geo clients.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 22:47:46 -05:00

32 lines
1.1 KiB
JavaScript

import { sql } from '../../../../lib/sql.js';
import { getPriceHistoryPoints } from '../../../../lib/pricing/price-history.js';
export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
try {
const cardId = parseInt(req.query.id, 10);
if (!req.query.id || Number.isNaN(cardId) || cardId <= 0) {
return res.status(400).json({ error: 'Valid card ID is required' });
}
const daysRaw = req.query.days ?? '90';
const days = parseInt(daysRaw, 10);
if (Number.isNaN(days) || days < 1 || days > 365) {
return res.status(400).json({ error: 'days must be between 1 and 365' });
}
const cardCheck = await sql`SELECT id FROM cards WHERE id = ${cardId}`;
if (cardCheck.rows.length === 0) {
return res.status(404).json({ error: 'Card not found' });
}
const points = await getPriceHistoryPoints(cardId, { days });
return res.status(200).json({ points });
} catch (err) {
console.error('[GET /api/cards/[id]/price-history]', err);
return res.status(500).json({ error: 'Internal server error' });
}
}