From 841502f9d1dbdd2ae395659db06c0b093e705e15 Mon Sep 17 00:00:00 2001 From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com> Date: Wed, 16 Jun 2021 09:20:40 +0200 Subject: [PATCH] BETTERZON-150: Fixing best deals API endpoint logic (#92) --- Backend/src/models/prices/prices.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Backend/src/models/prices/prices.service.ts b/Backend/src/models/prices/prices.service.ts index 3175b66..034131a 100644 --- a/Backend/src/models/prices/prices.service.ts +++ b/Backend/src/models/prices/prices.service.ts @@ -282,11 +282,11 @@ export const getBestDeals = async (amount: number): Promise => { 'price_in_cents': lowestPrice.price_in_cents, 'timestamp': lowestPrice.timestamp, 'amazonDifference': (amazonPrice.price_in_cents - lowestPrice.price_in_cents), - 'amazonDifferencePercent': ((1 - (lowestPrice.price_in_cents / amazonPrice.price_in_cents)) * 100), + 'amazonDifferencePercent': ((amazonPrice.price_in_cents / lowestPrice.price_in_cents) * 100), }; // Push only deals were the amazon price is actually higher - if (deal.amazonDifferencePercent > 0) { + if (deal.amazonDifferencePercent > 0 && deal.amazonDifference > 0) { deals.push(deal as Deal); } }