deckhearth/.convoys/pricing-online-local/brief-6-foil-aware-valuation.md

41 lines
1.5 KiB
Markdown
Raw Normal View History

---
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.