API /v1/auctions/lots: below_riv includes estimate-based deals
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 changed file +2 −1
modified
apps/api/src/lib/queries.ts
+2 −1
@@ -235,7 +235,8 @@ export async function auctionLots(opts: { status?: string; endingWithinHours?: n | ||
| 235 | 235 | if (opts.endingWithinHours) w.push(sql`l.ends_at between now() and now() + (${opts.endingWithinHours}::int || ' hours')::interval`); |
| 236 | 236 | if (opts.category) w.push(sql`(a.category_slug = ${opts.category} or a.family_slug = ${opts.category})`); |
| 237 | 237 | if (opts.house) w.push(sql`lower(au.auction_house) = lower(${opts.house})`); |
| 238 | − if (opts.belowRiv) w.push(sql`l.assessment_verdict = 'deal' and l.bid_vs_riv is not null`); | |
| 238 | + // estimate-based deals count too (a lot with no bid yet is compared on its all-in low estimate); the row says which via bid_vs_riv / estimate_vs_riv | |
| 239 | + if (opts.belowRiv) w.push(sql`l.assessment_verdict = 'deal' and coalesce(l.bid_vs_riv, l.estimate_vs_riv) is not null`); | |
| 239 | 240 | if (opts.assetId) w.push(sql`l.asset_id = ${opts.assetId}`); |
| 240 | 241 | const where = sql.join(w, sql` and `); |
| 241 | 242 | const order = opts.sort === 'discount' ? sql`coalesce(l.bid_vs_riv, l.estimate_vs_riv) asc nulls last, l.ends_at asc nulls last` : sql`l.ends_at asc nulls last`; |
| 242 | 243 | |