From cd4ed504dffc3190e5c0e98f7497da8b4ca640e8 Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Sat, 5 Nov 2022 08:10:15 +0800 Subject: [PATCH] [offers][fix] Fix user's offers appearing in own top relevant offers during analysis --- .../src/utils/offers/analysis/analysisGeneration.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/portal/src/utils/offers/analysis/analysisGeneration.ts b/apps/portal/src/utils/offers/analysis/analysisGeneration.ts index 484779ba..4fa5f917 100644 --- a/apps/portal/src/utils/offers/analysis/analysisGeneration.ts +++ b/apps/portal/src/utils/offers/analysis/analysisGeneration.ts @@ -251,6 +251,8 @@ export const generateAnalysis = async (params: { }, }); + const offerIds = offers.map((offer) => offer.id); + // COMPANY ANALYSIS const companyMap = new Map(); offers.forEach((offer) => { @@ -275,9 +277,9 @@ export const generateAnalysis = async (params: { ? 100 : 100 - (100 * companyIndex) / (similarCompanyOffers.length - 1); - // Get top offers (excluding user's offer) + // Get top offers (excluding user's offers) similarCompanyOffers = similarCompanyOffers.filter( - (offer) => offer.id !== companyOffer.id, + (offer) => !offerIds.includes(offer.id), ); const noOfSimilarCompanyOffers = similarCompanyOffers.length; @@ -311,9 +313,7 @@ export const generateAnalysis = async (params: { ? 100 : 100 - (100 * overallIndex) / (similarOffers.length - 1); - similarOffers = similarOffers.filter( - (offer) => offer.id !== overallHighestOffer.id, - ); + similarOffers = similarOffers.filter((offer) => !offerIds.includes(offer.id)); const noOfSimilarOffers = similarOffers.length; const similarOffers90PercentileIndex = Math.ceil(noOfSimilarOffers * 0.1);