Skip to content

Commit

Permalink
Merge pull request #46 from odevine/fix/allow-for-errors-when-calcula…
Browse files Browse the repository at this point in the history
…ting-price

Allow for usd_foil and usd_etched prices
  • Loading branch information
odevine authored Oct 5, 2024
2 parents 6db761b + e1376c0 commit 71597bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
21 changes: 11 additions & 10 deletions amplify/backend/function/pricecheck/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion amplify/team-provider-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/ToolsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const ToolsPage = (): JSX.Element => {
{`${cardTextStr}${cardSetCode}${cardCollectorNumber}`.toLowerCase()}
</Typography>
</Tooltip>
{line.price !== null && line.quantity !== null ? (
{line.price && line.quantity ? (
<Typography>
{line.quantity > 1 ? `($${line.price.toFixed(2)})` : ""}
&nbsp;${(line.price * line.quantity).toFixed(2)}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 71597bd

Please sign in to comment.