correct sort by market price by adding a back a roll-up market price from skus to product ID during sync

This commit is contained in:
Zach Harding
2026-03-25 14:31:46 -04:00
parent 3f9b1accda
commit 53cdddb183
3 changed files with 11 additions and 2 deletions

View File

@@ -94,7 +94,15 @@ export const upsertCardCollection = async (db:DBInstance) => {
with: { set: true, tcgdata: true, prices: true },
});
await client.collections('cards').documents().import(pokemon.map(card => {
const marketPrice = card.tcgdata?.marketPrice ? DollarToInt(card.tcgdata.marketPrice) : null;
// Use the NM SKU price matching the card's variant (kept fresh by syncPrices)
// Fall back to any NM sku, then to tcgdata price
const nmSku = card.prices.find(p => p.condition === 'Near Mint' && p.variant === card.variant)
?? card.prices.find(p => p.condition === 'Near Mint');
const marketPrice = nmSku?.marketPrice
? DollarToInt(nmSku.marketPrice)
: card.tcgdata?.marketPrice
? DollarToInt(card.tcgdata.marketPrice)
: null;
return {
id: card.cardId.toString(),