deckhearth/.convoys/pricing-online-local/brief-6-foil-aware-valuation.md
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

40 lines
1.5 KiB
Markdown

---
convoy: pricing-online-local
brief_number: 6
depends_on: [2]
recommended_model: composer-2.5
model_tier: standard
files:
- pages/api/user/stats.js
- pages/api/collections/[identifier].js
- test/api/user-stats-valuation.test.js
---
# Brief 6: Foil-aware valuation APIs
## Goal (1 sentence)
Fix collection total value to use nonfoil `current_price` for `user_cards.is_foil = false` rows.
## Files in scope (do not edit anything else)
- `pages/api/user/stats.js`
- `pages/api/collections/[identifier].js`
- `test/api/user-stats-valuation.test.js`
## Conventions to follow
- Import `effectiveUnitPriceExpr` and `listUnitPriceExpr` from `lib/pricing/collection-valuation.js`.
- `stats.js`: replace `cards.market_price * quantity` with effective unit price expression in value, game breakdown, rarity breakdown, and recent activity.
- `collections/[identifier].js`: replace `SUM(cards.market_price * cc.quantity)` with `listUnitPriceExpr`.
- Auth pattern unchanged (`getUserFromRequest`).
## Acceptance criteria
- [ ] Nonfoil `user_cards` row valued at `current_price`, not foil `market_price`
- [ ] Foil row still uses `market_price`
- [ ] Collection list totals use `COALESCE(current_price, market_price)`
- [ ] Regression test locks MTG foil/nonfoil scenario
- [ ] Tests pass
- [ ] No scope expansion
## Rationale (≤3 sentences)
This is the user-visible valuation bug from Phase 0. `market_price` stores Scryfall `usd_foil` for MTG. Fixing at the API layer immediately improves dashboard and profile totals.