From ce6733d1f913b6d5356f70a723c5efe9318795b1 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 2 Nov 2024 13:23:18 +0100 Subject: [PATCH] bugfixing --- .../stocks/[tickerID]/insider/+page.server.ts | 17 +++++++++++------ .../stocks/[tickerID]/insider/+page.svelte | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/routes/stocks/[tickerID]/insider/+page.server.ts b/src/routes/stocks/[tickerID]/insider/+page.server.ts index b098220c..7688a8c5 100644 --- a/src/routes/stocks/[tickerID]/insider/+page.server.ts +++ b/src/routes/stocks/[tickerID]/insider/+page.server.ts @@ -21,7 +21,7 @@ const transactionTypeMap = { }; export const load = async ({ locals, params }) => { - const { apiURL, apiKey } = locals; + const { apiURL, apiKey, user } = locals; const getInsiderTrading = async () => { const postData = { @@ -40,6 +40,8 @@ export const load = async ({ locals, params }) => { let output = await response.json(); + output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; + output = output?.reduce((acc, item) => { const newTransactionType = typeof transactionTypeMap[item?.transactionType] === "function" @@ -48,11 +50,14 @@ export const load = async ({ locals, params }) => { // Only include items with 'Bought' or 'Sold' if (newTransactionType === "Bought" || newTransactionType === "Sold") { - acc.push({ - ...item, - transactionType: newTransactionType, - value: item?.securitiesTransacted * item?.price, // new key 'value' - }); + const value = item?.securitiesTransacted * item?.price; + if (value > 0) { + acc.push({ + ...item, + transactionType: newTransactionType, + value: value, // new key 'value' + }); + } } return acc; diff --git a/src/routes/stocks/[tickerID]/insider/+page.svelte b/src/routes/stocks/[tickerID]/insider/+page.svelte index 53650d2e..e0599b4d 100644 --- a/src/routes/stocks/[tickerID]/insider/+page.svelte +++ b/src/routes/stocks/[tickerID]/insider/+page.svelte @@ -596,11 +596,11 @@ - {#each data?.user?.tier === "Pro" ? insiderTradingList : insiderTradingList?.slice(0, 3) as item, index} + {#each insiderTradingList as item, index} {#if item?.price > 0} - {#if rawData?.length === insiderTradingList?.length} + {#if rawData?.length === insiderTradingList?.length && data?.user?.tier === "Pro"}