--- import { client } from '../../db/typesense.ts'; import { db } from '../../db'; import RarityIcon from '../../components/RarityIcon.astro'; export const prerender = false; // get the query from post request using form data const formData = await Astro.request.formData(); const query = formData.get('q')?.toString() || ''; const start = Number(formData.get('start')?.toString() || '0'); // use typesense to search for cards matching the query and return the productIds of the results const searchResults = await client.collections('cards').documents().search({ q: query, filter_by: 'sealed:false', query_by: 'productLineName,productName,setName,number,rarityName,Artist', per_page: 20, page: Math.floor(start / 20) + 1, }); const productIds = searchResults.hits?.map((hit: any) => hit.document.productId) ?? []; const totalHits = searchResults.found; // 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, } }); // format price to 2 decimal places (or 0 if price >=100) and adds a $ sign, if the price is null it returns "–" const formatPrice = (price:any) => { if (price === null) { return "—"; } price = Number(price); if (price > 99.99) return `$${Math.round(price)}`; return `$${price.toFixed(2)}`; }; const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"]; --- {(start === 0) && } {pokemon.map((card) => (