From e1376c086a92d42270bfd44a0e72b2a5a7896fa0 Mon Sep 17 00:00:00 2001 From: Owen Devine Date: Sat, 5 Oct 2024 13:23:00 -0400 Subject: [PATCH] fix: allow for usd_foil and usd_etched prices to supersede regular usd prices --- .../backend/function/pricecheck/src/app.js | 21 ++++++++++--------- amplify/team-provider-info.json | 2 +- src/Pages/ToolsPage.tsx | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/amplify/backend/function/pricecheck/src/app.js b/amplify/backend/function/pricecheck/src/app.js index 358880d..5ce7805 100644 --- a/amplify/backend/function/pricecheck/src/app.js +++ b/amplify/backend/function/pricecheck/src/app.js @@ -39,19 +39,20 @@ const findLowestUsdPrice = (cards) => { let lowestPriceData = null; cards.forEach((card) => { - // Check if the card has a valid USD price and is not included in an illegal set - if ( - card.prices && - card.prices.usd && - !ILLEGAL_SETS.includes(card.set.toLowerCase()) - ) { - const cardPrice = parseFloat(card.prices.usd); + // Parse the available prices and find the lowest + const usdPrice = card.prices.usd ? parseFloat(card.prices.usd) : null; + const usdFoilPrice = card.prices.usd_foil ? parseFloat(card.prices.usd_foil) : null; + const usdEtchedPrice = card.prices.usd_etched ? parseFloat(card.prices.usd_etched) : null; + const availablePrices = [usdPrice, usdFoilPrice, usdEtchedPrice].filter(price => price !== null); + + if (!ILLEGAL_SETS.includes(card.set.toLowerCase()) && availablePrices.length > 0) { + const lowestPrice = Math.min(...availablePrices); // Update the lowest price data if needed - if (lowestPriceData === null || cardPrice < lowestPriceData.price) { + if (lowestPriceData === null || lowestPrice < lowestPriceData.price) { lowestPriceData = { name: card.name, - price: cardPrice, + price: lowestPrice, setCode: card.set.toLowerCase(), collectorNumber: card.collector_number.toLowerCase(), }; @@ -292,7 +293,7 @@ app.post("/priceCheck", async function (req, res) { const { tag, name, ...rest } = isCycleLand; cardData = { ...rest, - priceNote: `cheapest land in cycle '${tag}'`, + priceNote: `cheapest land in '${tag}'`, }; alternateCardName = name.toLowerCase(); diff --git a/amplify/team-provider-info.json b/amplify/team-provider-info.json index 289ce38..81ca272 100644 --- a/amplify/team-provider-info.json +++ b/amplify/team-provider-info.json @@ -23,7 +23,7 @@ "function": { "pricecheck": { "deploymentBucketName": "amplify-edhtracker-master-c66d9-deployment", - "s3Key": "amplify-builds/pricecheck-44777346324557716875-build.zip" + "s3Key": "amplify-builds/pricecheck-6265737a5530387a5555-build.zip" } }, "storage": { diff --git a/src/Pages/ToolsPage.tsx b/src/Pages/ToolsPage.tsx index 43087ef..19dd35b 100644 --- a/src/Pages/ToolsPage.tsx +++ b/src/Pages/ToolsPage.tsx @@ -301,7 +301,7 @@ export const ToolsPage = (): JSX.Element => { {`${cardTextStr}${cardSetCode}${cardCollectorNumber}`.toLowerCase()} - {line.price !== null && line.quantity !== null ? ( + {line.price && line.quantity ? ( {line.quantity > 1 ? `($${line.price.toFixed(2)})` : ""}  ${(line.price * line.quantity).toFixed(2)} @@ -345,7 +345,7 @@ export const ToolsPage = (): JSX.Element => { {(() => { const total = priceCheckResponse.reduce( (acc, card) => - card.price !== null && card.quantity !== null + card.price && card.quantity ? acc + card.price * card.quantity : acc, 0,