diff --git a/scripts/indexing.ts b/scripts/indexing.ts index 2aaf4e6..8b003dc 100644 --- a/scripts/indexing.ts +++ b/scripts/indexing.ts @@ -31,11 +31,11 @@ export const createCardCollection = async () => { { name: 'number', type: 'string', sort: true }, { name: 'Artist', type: 'string' }, { name: 'sealed', type: 'bool' }, - { name: 'releaseDate', type: 'int32'}, + { name: 'releaseDate', type: 'int32' }, + { name: 'marketPrice', type: 'int32', optional: true, sort: true }, { name: 'content', type: 'string', token_separators: ['/'] }, { name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true } ], - //default_sorting_field: 'productId', }); console.log(chalk.green('Collection "cards" created successfully.')); } @@ -65,24 +65,29 @@ export const upsertCardCollection = async (db:DBInstance) => { const pokemon = await db.query.cards.findMany({ with: { set: true, tcgdata: true, prices: true }, }); - await client.collections('cards').documents().import(pokemon.map(card => ({ - id: card.cardId.toString(), - cardId: card.cardId, - productId: card.productId, - variant: card.variant, - productName: card.productName, - productLineName: card.productLineName, - rarityName: card.rarityName, - setName: card.set?.setName || "", - cardType: card.cardType || "", - energyType: card.energyType || "", - number: card.number, - Artist: card.artist || "", - sealed: card.sealed, - content: [card.productName,card.productLineName,card.set?.setName || "",card.number,card.rarityName,card.artist || ""].join(' '), - releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0, - sku_id: card.prices.map(price => price.skuId.toString()) - })), { action: 'upsert' }); + await client.collections('cards').documents().import(pokemon.map(card => { + const marketPrice = card.tcgdata?.marketPrice ? DollarToInt(card.tcgdata.marketPrice) : null; + + return { + id: card.cardId.toString(), + cardId: card.cardId, + productId: card.productId, + variant: card.variant, + productName: card.productName, + productLineName: card.productLineName, + rarityName: card.rarityName, + setName: card.set?.setName || "", + cardType: card.cardType || "", + energyType: card.energyType || "", + number: card.number, + Artist: card.artist || "", + sealed: card.sealed, + content: [card.productName, card.productLineName, card.set?.setName || "", card.number, card.rarityName, card.artist || ""].join(' '), + releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0, + ...(marketPrice !== null && { marketPrice }), + sku_id: card.prices.map(price => price.skuId.toString()) + }; + }), { action: 'upsert' }); console.log(chalk.green('Collection "cards" indexed successfully.')); } diff --git a/src/components/CardGrid.astro b/src/components/CardGrid.astro index 7ceb61b..284842b 100644 --- a/src/components/CardGrid.astro +++ b/src/components/CardGrid.astro @@ -16,18 +16,8 @@ import BackToTop from "./BackToTop.astro"
- +
+
@@ -57,6 +47,55 @@ import BackToTop from "./BackToTop.astro"