--- //import { eq } from 'drizzle-orm'; import { isConditionalExpression } from 'typescript'; import { client } from '../db/typesense.ts'; import { db } from '../db'; import RarityIcon from './RarityIcon.astro'; import EnergyIcon from './EnergyIcon.astro'; //import * as schema from '../db/schema.ts'; const { query } = Astro.props; const searchResults = await client.collections('cards').documents().search({ q: query, query_by: 'productLineName,productName,setName,number,rarityName,Artist', per_page: 250, }); const productIds = searchResults.hits?.map((hit: any) => hit.document.productId) ?? []; // get pokemon data with prices and set info using searchResults and then query the database for each card to get the prices and set info const pokemon = await db.query.cards.findMany({ where: { productId: { in: productIds, }, }, with: { prices: true, set: true, } }); const formatPrice = (price:any) => { if (price === null) { return "–"; } price = Number(price); if (price >= 99.99) { return `${Math.round(price)}`; } return `${price.toFixed(2)}`; }; const order = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"]; --- {pokemon.map((card) => (
{card.productName}
{card.prices .slice() .sort((a, b) => order.indexOf(a.condition) - order.indexOf(b.condition)) .filter((price, index, arr) => arr.findIndex(p => p.condition === price.condition) === index ) .map((price) => (
{price.condition.split(' ').map((w) => w[0]).join('')}
${formatPrice(price.marketPrice)}
))}
{card.productName}
{card.set?.setCode}
{card.number}
))}