From 8d5b87f1ca9e4c185e5b1b6a0aef869bc1259c00 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 20 Sep 2024 01:14:48 +0200 Subject: [PATCH] convert +page.ts to +page.server.ts --- src/routes/analysts/+page.server.ts | 26 ++++ src/routes/analysts/+page.svelte | 2 +- src/routes/analysts/+page.ts | 34 ----- src/routes/analysts/[slug]/+page.server.ts | 27 ++++ src/routes/analysts/[slug]/+page.ts | 38 ----- .../analysts/top-stocks/+page.server.ts | 25 ++++ src/routes/analysts/top-stocks/+page.ts | 33 ---- .../+page.server.ts | 26 ++++ .../corporate-lobbying-tracker/+page.ts | 34 ----- src/routes/cramer-tracker/+page.server.ts | 26 ++++ src/routes/cramer-tracker/+page.ts | 36 ----- src/routes/dividends-calendar/+page.server.ts | 23 +++ src/routes/dividends-calendar/+page.ts | 35 ----- src/routes/earnings-calendar/+page.server.ts | 23 +++ src/routes/earnings-calendar/+page.ts | 35 ----- src/routes/economic-calendar/+page.server.ts | 23 +++ src/routes/economic-calendar/+page.ts | 35 ----- src/routes/economic-indicator/+page.server.ts | 24 +++ src/routes/economic-indicator/+page.ts | 32 ---- .../hedge-funds/{+page.ts => +page.server.ts} | 14 +- .../[slug]/{+page.ts => +page.server.ts} | 18 +-- src/routes/hedge-funds/[slug]/+page.svelte | 2 + src/routes/industry/+page.server.ts | 23 +++ src/routes/industry/+page.ts | 34 ----- src/routes/industry/all/+page.server.ts | 23 +++ src/routes/industry/all/+page.ts | 34 ----- src/routes/industry/sectors/+page.server.ts | 24 +++ src/routes/industry/sectors/+page.ts | 34 ----- .../list/industry/[slug]/+page.server.ts | 29 ++++ src/routes/list/industry/[slug]/+page.ts | 38 ----- src/routes/market-mover/+page.server.ts | 38 +++++ src/routes/market-mover/+page.ts | 61 -------- src/routes/market-news/+page.server.ts | 24 +++ src/routes/market-news/+page.ts | 37 ----- .../market-news/general/+page.server.ts | 25 ++++ src/routes/market-news/general/+page.ts | 38 ----- src/routes/most-retail-volume/+page.server.ts | 26 ++++ src/routes/most-retail-volume/+page.ts | 35 ----- .../most-shorted-stocks/+page.server.ts | 25 ++++ src/routes/most-shorted-stocks/+page.ts | 34 ----- src/routes/options-flow/+page.server.ts | 22 +++ src/routes/options-flow/+page.ts | 24 +-- src/routes/politicians/+page.server.ts | 50 +++++++ src/routes/politicians/+page.ts | 59 -------- .../politicians/flow-data/+page.server.ts | 50 +++++++ src/routes/politicians/flow-data/+page.ts | 58 ------- src/routes/price-alert/+page.server.ts | 40 +++++ src/routes/price-alert/+page.svelte | 22 +-- src/routes/price-alert/+page.ts | 34 ----- src/routes/sitemap.xml/+server.ts | 12 +- .../stock-splits-calendar/+page.server.ts | 23 +++ src/routes/stock-splits-calendar/+page.ts | 35 ----- src/routes/stocks/+page.server.ts | 23 +++ src/routes/stocks/+page.ts | 35 ----- .../[tickerID]/dividends/+page.server.ts | 30 ++++ .../stocks/[tickerID]/dividends/+page.ts | 41 ----- .../[tickerID]/forecast/+page.server.ts | 28 ++++ .../stocks/[tickerID]/forecast/+page.ts | 39 ----- .../[tickerID]/forecast/ai/+page.server.ts | 28 ++++ .../stocks/[tickerID]/forecast/ai/+page.ts | 39 ----- .../forecast/analyst/+page.server.ts | 28 ++++ .../[tickerID]/forecast/analyst/+page.ts | 39 ----- .../stocks/[tickerID]/insider/+page.server.ts | 112 ++++++++++++++ src/routes/stocks/[tickerID]/insider/+page.ts | 141 ------------------ .../insider/congress-trading/+page.server.ts | 28 ++++ .../insider/congress-trading/+page.ts | 41 ----- .../insider/transcripts/+page.server.ts | 38 +++++ .../[tickerID]/insider/transcripts/+page.ts | 56 ------- .../stocks/[tickerID]/news/+page.server.ts | 28 ++++ .../stocks/[tickerID]/news/+page.svelte | 8 +- src/routes/stocks/[tickerID]/news/+page.ts | 41 ----- .../stocks/[tickerID]/options/+page.server.ts | 94 ++++++++++++ src/routes/stocks/[tickerID]/options/+page.ts | 122 --------------- .../stocks/[tickerID]/stats/+page.server.ts | 35 ++++- src/routes/stocks/[tickerID]/stats/+page.ts | 41 ----- .../stats/balance-sheet/+page.server.ts | 29 ++++ .../[tickerID]/stats/balance-sheet/+page.ts | 40 ----- .../stats/cash-flow/+page.server.ts | 28 ++++ .../[tickerID]/stats/cash-flow/+page.ts | 41 ----- .../stats/employees/+page.server.ts | 27 ++++ .../[tickerID]/stats/employees/+page.ts | 39 ----- .../[tickerID]/stats/income/+page.server.ts | 27 ++++ .../stocks/[tickerID]/stats/income/+page.ts | 40 ----- .../stats/market-cap/+page.server.ts | 27 ++++ .../[tickerID]/stats/market-cap/+page.svelte | 1 + .../[tickerID]/stats/market-cap/+page.ts | 40 ----- .../[tickerID]/stats/ratios/+page.server.ts | 28 ++++ .../stocks/[tickerID]/stats/ratios/+page.ts | 41 ----- 88 files changed, 1303 insertions(+), 1802 deletions(-) create mode 100644 src/routes/analysts/+page.server.ts delete mode 100644 src/routes/analysts/+page.ts create mode 100644 src/routes/analysts/[slug]/+page.server.ts delete mode 100644 src/routes/analysts/[slug]/+page.ts create mode 100644 src/routes/analysts/top-stocks/+page.server.ts delete mode 100644 src/routes/analysts/top-stocks/+page.ts create mode 100644 src/routes/corporate-lobbying-tracker/+page.server.ts delete mode 100644 src/routes/corporate-lobbying-tracker/+page.ts create mode 100644 src/routes/cramer-tracker/+page.server.ts delete mode 100644 src/routes/cramer-tracker/+page.ts create mode 100644 src/routes/dividends-calendar/+page.server.ts delete mode 100644 src/routes/dividends-calendar/+page.ts create mode 100644 src/routes/earnings-calendar/+page.server.ts delete mode 100644 src/routes/earnings-calendar/+page.ts create mode 100644 src/routes/economic-calendar/+page.server.ts delete mode 100644 src/routes/economic-calendar/+page.ts create mode 100644 src/routes/economic-indicator/+page.server.ts delete mode 100644 src/routes/economic-indicator/+page.ts rename src/routes/hedge-funds/{+page.ts => +page.server.ts} (57%) rename src/routes/hedge-funds/[slug]/{+page.ts => +page.server.ts} (59%) create mode 100644 src/routes/industry/+page.server.ts delete mode 100644 src/routes/industry/+page.ts create mode 100644 src/routes/industry/all/+page.server.ts delete mode 100644 src/routes/industry/all/+page.ts create mode 100644 src/routes/industry/sectors/+page.server.ts delete mode 100644 src/routes/industry/sectors/+page.ts create mode 100644 src/routes/list/industry/[slug]/+page.server.ts delete mode 100644 src/routes/list/industry/[slug]/+page.ts create mode 100644 src/routes/market-mover/+page.server.ts delete mode 100644 src/routes/market-mover/+page.ts create mode 100644 src/routes/market-news/+page.server.ts delete mode 100644 src/routes/market-news/+page.ts create mode 100644 src/routes/market-news/general/+page.server.ts delete mode 100644 src/routes/market-news/general/+page.ts create mode 100644 src/routes/most-retail-volume/+page.server.ts delete mode 100644 src/routes/most-retail-volume/+page.ts create mode 100644 src/routes/most-shorted-stocks/+page.server.ts delete mode 100644 src/routes/most-shorted-stocks/+page.ts create mode 100644 src/routes/options-flow/+page.server.ts create mode 100644 src/routes/politicians/+page.server.ts delete mode 100644 src/routes/politicians/+page.ts create mode 100644 src/routes/politicians/flow-data/+page.server.ts delete mode 100644 src/routes/politicians/flow-data/+page.ts create mode 100644 src/routes/price-alert/+page.server.ts delete mode 100644 src/routes/price-alert/+page.ts create mode 100644 src/routes/stock-splits-calendar/+page.server.ts delete mode 100644 src/routes/stock-splits-calendar/+page.ts create mode 100644 src/routes/stocks/+page.server.ts delete mode 100644 src/routes/stocks/+page.ts create mode 100644 src/routes/stocks/[tickerID]/dividends/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/dividends/+page.ts create mode 100644 src/routes/stocks/[tickerID]/forecast/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/forecast/+page.ts create mode 100644 src/routes/stocks/[tickerID]/forecast/ai/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/forecast/ai/+page.ts create mode 100644 src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/forecast/analyst/+page.ts create mode 100644 src/routes/stocks/[tickerID]/insider/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/insider/+page.ts create mode 100644 src/routes/stocks/[tickerID]/insider/congress-trading/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/insider/congress-trading/+page.ts create mode 100644 src/routes/stocks/[tickerID]/insider/transcripts/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/insider/transcripts/+page.ts create mode 100644 src/routes/stocks/[tickerID]/news/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/news/+page.ts create mode 100644 src/routes/stocks/[tickerID]/options/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/options/+page.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/balance-sheet/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/balance-sheet/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/cash-flow/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/cash-flow/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/employees/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/employees/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/income/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/income/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/market-cap/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/market-cap/+page.ts create mode 100644 src/routes/stocks/[tickerID]/stats/ratios/+page.server.ts delete mode 100644 src/routes/stocks/[tickerID]/stats/ratios/+page.ts diff --git a/src/routes/analysts/+page.server.ts b/src/routes/analysts/+page.server.ts new file mode 100644 index 00000000..4dcab307 --- /dev/null +++ b/src/routes/analysts/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, setHeaders }) => { + const getTopAnalyst = async () => { + const { apiURL, apiKey, user } = locals; + + const response = await fetch(apiURL + "/top-analysts", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response?.json(); + + output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output; + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getTopAnalyst: await getTopAnalyst(), + }; +}; diff --git a/src/routes/analysts/+page.svelte b/src/routes/analysts/+page.svelte index 7049eb04..2bea83d5 100644 --- a/src/routes/analysts/+page.svelte +++ b/src/routes/analysts/+page.svelte @@ -157,7 +157,7 @@ $: { diff --git a/src/routes/analysts/+page.ts b/src/routes/analysts/+page.ts deleted file mode 100644 index 8a1d3825..00000000 --- a/src/routes/analysts/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getTopAnalyst = async () => { - const { apiURL, apiKey, user } = await parent(); - - let output; - - const cachedData = getCache("", "getTopAnalyst"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/top-analysts", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response?.json(); - setCache("", output, "getTopAnalyst"); - } - - output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getTopAnalyst: await getTopAnalyst(), - }; -}; diff --git a/src/routes/analysts/[slug]/+page.server.ts b/src/routes/analysts/[slug]/+page.server.ts new file mode 100644 index 00000000..9fce74b7 --- /dev/null +++ b/src/routes/analysts/[slug]/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, setHeaders, params }) => { + const getAnalystStats = async () => { + const { apiURL, apiKey } = locals; + + const postData = { analystId: params.slug }; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/analyst-stats", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + let output = await response.json(); + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getAnalystStats: await getAnalystStats(), + }; +}; diff --git a/src/routes/analysts/[slug]/+page.ts b/src/routes/analysts/[slug]/+page.ts deleted file mode 100644 index 888c0595..00000000 --- a/src/routes/analysts/[slug]/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getAnalystStats = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.slug, "getAnalystStats"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { analystId: params.slug }; - // make the POST request to the endpoint - const response = await fetch(apiURL + "/analyst-stats", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getAnalystStats' - setCache(params.slug, output, "getAnalystStats"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAnalystStats: await getAnalystStats(), - }; -}; diff --git a/src/routes/analysts/top-stocks/+page.server.ts b/src/routes/analysts/top-stocks/+page.server.ts new file mode 100644 index 00000000..face3203 --- /dev/null +++ b/src/routes/analysts/top-stocks/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals, setHeaders }) => { + const getTopAnalystStocks = async () => { + const { apiURL, apiKey, user } = locals; + + const response = await fetch(apiURL + "/top-analysts-stocks", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response.json(); + + output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output; + + setHeaders({ "cache-control": "public, max-age=3000" }); + return output; + }; + + // Make sure to return a promise + return { + getTopAnalystStocks: await getTopAnalystStocks(), + }; +}; diff --git a/src/routes/analysts/top-stocks/+page.ts b/src/routes/analysts/top-stocks/+page.ts deleted file mode 100644 index ea3c90b6..00000000 --- a/src/routes/analysts/top-stocks/+page.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getTopAnalystStocks = async () => { - let output; - const { apiURL, apiKey, user } = await parent(); - - const cachedData = getCache("", "getTopAnalystStocks"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/top-analysts-stocks", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getTopAnalystStocksg"); - } - - output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output; - return output; - }; - - // Make sure to return a promise - return { - getTopAnalystStocks: await getTopAnalystStocks(), - }; -}; diff --git a/src/routes/corporate-lobbying-tracker/+page.server.ts b/src/routes/corporate-lobbying-tracker/+page.server.ts new file mode 100644 index 00000000..8bc62cb8 --- /dev/null +++ b/src/routes/corporate-lobbying-tracker/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, setHeaders }) => { + const getCorporateLobbyingTracker = async () => { + const { apiKey, apiURL, user } = locals; + + const response = await fetch(apiURL + "/lobbying-tracker", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response.json(); + + output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getCorporateLobbyingTracker: await getCorporateLobbyingTracker(), + }; +}; diff --git a/src/routes/corporate-lobbying-tracker/+page.ts b/src/routes/corporate-lobbying-tracker/+page.ts deleted file mode 100644 index 60bc39a2..00000000 --- a/src/routes/corporate-lobbying-tracker/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getCorporateLobbyingTracker = async () => { - let output; - const { apiKey, apiURL, user } = await parent(); - - const cachedData = getCache("", "getCorporateLobbyingTracker"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/lobbying-tracker", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getCorporateLobbyingTracker"); - } - - output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getCorporateLobbyingTracker: await getCorporateLobbyingTracker(), - }; -}; diff --git a/src/routes/cramer-tracker/+page.server.ts b/src/routes/cramer-tracker/+page.server.ts new file mode 100644 index 00000000..6de70b33 --- /dev/null +++ b/src/routes/cramer-tracker/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, setHeaders }) => { + const getCramerTracker = async () => { + const { apiKey, apiURL, user } = locals; + + const response = await fetch(apiURL + "/cramer-tracker", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response.json(); + + output = user?.tier !== "Pro" ? output?.slice(0, 5) : output; + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getCramerTracker: await getCramerTracker(), + }; +}; diff --git a/src/routes/cramer-tracker/+page.ts b/src/routes/cramer-tracker/+page.ts deleted file mode 100644 index 09ae31c3..00000000 --- a/src/routes/cramer-tracker/+page.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getCramerTracker = async () => { - let output; - const { apiKey, apiURL, user } = await parent(); - - const cachedData = getCache("", "getCramerTracker"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/cramer-tracker", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getCramerTracker"); - } - - output = user?.tier !== "Pro" ? output?.slice(0, 5) : output; - - //output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getCramerTracker: await getCramerTracker(), - }; -}; diff --git a/src/routes/dividends-calendar/+page.server.ts b/src/routes/dividends-calendar/+page.server.ts new file mode 100644 index 00000000..8fdfd989 --- /dev/null +++ b/src/routes/dividends-calendar/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getDividendCalendar = async () => { + const { apiKey, apiURL } = locals; + const response = await fetch(apiURL + "/dividends-calendar", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getDividendCalendar: await getDividendCalendar(), + }; +}; diff --git a/src/routes/dividends-calendar/+page.ts b/src/routes/dividends-calendar/+page.ts deleted file mode 100644 index c11158d8..00000000 --- a/src/routes/dividends-calendar/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getDividendCalendar = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDividendCalendar"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/dividends-calendar", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getDividendCalendar' - setCache("", output, "getDividendCalendar"); - } - - return output; - }; - - // Make sure to return a promise - return { - getDividendCalendar: await getDividendCalendar(), - }; -}; diff --git a/src/routes/earnings-calendar/+page.server.ts b/src/routes/earnings-calendar/+page.server.ts new file mode 100644 index 00000000..49c3356b --- /dev/null +++ b/src/routes/earnings-calendar/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getEarningsCalendar = async () => { + const { apiKey, apiURL } = locals; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/earnings-calendar", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getEarningsCalendar: await getEarningsCalendar(), + }; +}; diff --git a/src/routes/earnings-calendar/+page.ts b/src/routes/earnings-calendar/+page.ts deleted file mode 100644 index be22b181..00000000 --- a/src/routes/earnings-calendar/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getEarningsCalendar = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getEarningsCalendar"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/earnings-calendar", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getEarningsCalendar' - setCache("", output, "getEarningsCalendar"); - } - - return output; - }; - - // Make sure to return a promise - return { - getEarningsCalendar: await getEarningsCalendar(), - }; -}; diff --git a/src/routes/economic-calendar/+page.server.ts b/src/routes/economic-calendar/+page.server.ts new file mode 100644 index 00000000..11ebe88f --- /dev/null +++ b/src/routes/economic-calendar/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getEconomicCalendar = async () => { + const { apiURL, apiKey } = locals; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/economic-calendar", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getEconomicCalendar: await getEconomicCalendar(), + }; +}; diff --git a/src/routes/economic-calendar/+page.ts b/src/routes/economic-calendar/+page.ts deleted file mode 100644 index 52555e2a..00000000 --- a/src/routes/economic-calendar/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getEconomicCalendar = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getEconomicCalendar"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/economic-calendar", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getEconomicCalendar' - setCache("", output, "getEconomicCalendar"); - } - - return output; - }; - - // Make sure to return a promise - return { - getEconomicCalendar: await getEconomicCalendar(), - }; -}; diff --git a/src/routes/economic-indicator/+page.server.ts b/src/routes/economic-indicator/+page.server.ts new file mode 100644 index 00000000..5a6fd03c --- /dev/null +++ b/src/routes/economic-indicator/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals, setHeaders }) => { + const getEconomicIndicator = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/economic-indicator", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getEconomicIndicator: await getEconomicIndicator(), + }; +}; diff --git a/src/routes/economic-indicator/+page.ts b/src/routes/economic-indicator/+page.ts deleted file mode 100644 index c1dcb776..00000000 --- a/src/routes/economic-indicator/+page.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getEconomicIndicator = async () => { - let output; - const { apiKey, apiURL } = await parent(); - - const cachedData = getCache("", "getEconomicIndicator"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/economic-indicator", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getEconomicIndicator"); - } - - return output; - }; - - // Make sure to return a promise - return { - getEconomicIndicator: await getEconomicIndicator(), - }; -}; diff --git a/src/routes/hedge-funds/+page.ts b/src/routes/hedge-funds/+page.server.ts similarity index 57% rename from src/routes/hedge-funds/+page.ts rename to src/routes/hedge-funds/+page.server.ts index eb3635a3..bc83295c 100644 --- a/src/routes/hedge-funds/+page.ts +++ b/src/routes/hedge-funds/+page.server.ts @@ -1,14 +1,6 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { +export const load = async ({ locals, setHeaders }) => { const getAllHedgeFunds = async () => { - const cachedData = getCache("", "getAllHedgeFunds"); - - if (cachedData) { - return cachedData; - } - - const { apiURL, apiKey } = await parent(); + const { apiURL, apiKey } = locals; const response = await fetch(apiURL + "/all-hedge-funds", { method: "GET", headers: { @@ -18,8 +10,8 @@ export const load = async ({ parent }) => { }); const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); - setCache("", output, "getAllHedgeFunds"); return output; }; diff --git a/src/routes/hedge-funds/[slug]/+page.ts b/src/routes/hedge-funds/[slug]/+page.server.ts similarity index 59% rename from src/routes/hedge-funds/[slug]/+page.ts rename to src/routes/hedge-funds/[slug]/+page.server.ts index 26c6fa7b..555ffaf6 100644 --- a/src/routes/hedge-funds/[slug]/+page.ts +++ b/src/routes/hedge-funds/[slug]/+page.server.ts @@ -1,20 +1,12 @@ import { displayCompanyName, getCache, setCache } from "$lib/store"; -export const load = async ({ parent, params }) => { +export const load = async ({ params, locals, setHeaders }) => { const getCIKNumber = async () => { return params.slug; }; const getHedgeFundsData = async () => { - const cachedData = getCache(params.slug, "getHedgeFundsData"); - - if (cachedData) { - displayCompanyName.update(() => cachedData?.name ?? params.slug); - - return cachedData; - } - - const { apiURL, apiKey } = await parent(); + const { apiURL, apiKey } = locals; const response = await fetch(apiURL + "/cik-data", { method: "POST", headers: { @@ -28,12 +20,12 @@ export const load = async ({ parent, params }) => { if (output?.holdings) { output.holdings = output?.holdings?.filter( - (item) => item?.sharesNumber && item?.symbol, + (item) => item?.sharesNumber && item?.symbol ); } - displayCompanyName.update(() => output?.name ?? params.slug); + //displayCompanyName.update(() => output?.name ?? params.slug); + setHeaders({ "cache-control": "public, max-age=3000" }); - setCache(params.slug, output, "getHedgeFundsData"); return output; }; diff --git a/src/routes/hedge-funds/[slug]/+page.svelte b/src/routes/hedge-funds/[slug]/+page.svelte index 8811dda7..64cf70b7 100644 --- a/src/routes/hedge-funds/[slug]/+page.svelte +++ b/src/routes/hedge-funds/[slug]/+page.svelte @@ -20,6 +20,7 @@ use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]) export let data; let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL; + function sectorSelector(sector) { let path; @@ -73,6 +74,7 @@ use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]) let isLoaded = false; let rawData = data?.getHedgeFundsData; + displayCompanyName.update(() => rawData?.name ?? 'Company Data') let rawList = [] let displayList = []; let optionsData = {}; diff --git a/src/routes/industry/+page.server.ts b/src/routes/industry/+page.server.ts new file mode 100644 index 00000000..0174f846 --- /dev/null +++ b/src/routes/industry/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getSectorIndustryOverview = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/sector-industry-overview", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response?.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getSectorIndustryOverview: await getSectorIndustryOverview(), + }; +}; diff --git a/src/routes/industry/+page.ts b/src/routes/industry/+page.ts deleted file mode 100644 index 9cc73b93..00000000 --- a/src/routes/industry/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getSectorIndustryOverview = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getSectorIndustryOverview"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/sector-industry-overview", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getSectorIndustryOverview"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSectorIndustryOverview: await getSectorIndustryOverview(), - }; -}; diff --git a/src/routes/industry/all/+page.server.ts b/src/routes/industry/all/+page.server.ts new file mode 100644 index 00000000..03079c11 --- /dev/null +++ b/src/routes/industry/all/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getIndustryOverview = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/industry-overview", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getIndustryOverview: await getIndustryOverview(), + }; +}; diff --git a/src/routes/industry/all/+page.ts b/src/routes/industry/all/+page.ts deleted file mode 100644 index 251bdd1b..00000000 --- a/src/routes/industry/all/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getIndustryOverview = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getIndustryOverview"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/industry-overview", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getIndustryOverview"); - } - - return output; - }; - - // Make sure to return a promise - return { - getIndustryOverview: await getIndustryOverview(), - }; -}; diff --git a/src/routes/industry/sectors/+page.server.ts b/src/routes/industry/sectors/+page.server.ts new file mode 100644 index 00000000..cf77b853 --- /dev/null +++ b/src/routes/industry/sectors/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals, setHeaders }) => { + const getSectorOverview = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/sector-overview", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getSectorOverview: await getSectorOverview(), + }; +}; diff --git a/src/routes/industry/sectors/+page.ts b/src/routes/industry/sectors/+page.ts deleted file mode 100644 index c2fadd39..00000000 --- a/src/routes/industry/sectors/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getSectorOverview = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getSectorOverview"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/sector-overview", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getSectorOverview"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSectorOverview: await getSectorOverview(), - }; -}; diff --git a/src/routes/list/industry/[slug]/+page.server.ts b/src/routes/list/industry/[slug]/+page.server.ts new file mode 100644 index 00000000..fdf057fd --- /dev/null +++ b/src/routes/list/industry/[slug]/+page.server.ts @@ -0,0 +1,29 @@ +export const load = async ({ params, locals, setHeaders }) => { + const getIndustryStocks = async () => { + const { apiKey, apiURL } = locals; + + const postData = { ticker: params.slug }; + const response = await fetch(apiURL + "/industry-stocks", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + //output = user?.tier !== "Pro" ? output?.slice(0, 5) : output; + + //output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output; + + return output; + }; + + // Make sure to return a promise + return { + getIndustryStocks: await getIndustryStocks(), + }; +}; diff --git a/src/routes/list/industry/[slug]/+page.ts b/src/routes/list/industry/[slug]/+page.ts deleted file mode 100644 index 658a7476..00000000 --- a/src/routes/list/industry/[slug]/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getIndustryStocks = async () => { - let output; - const { apiKey, apiURL } = await parent(); - - const cachedData = getCache(params.slug, "getIndustryStocks"); - if (cachedData) { - output = cachedData; - } else { - const postData = { ticker: params.slug }; - const response = await fetch(apiURL + "/industry-stocks", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.slug, output, "getIndustryStocks"); - } - - //output = user?.tier !== "Pro" ? output?.slice(0, 5) : output; - - //output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getIndustryStocks: await getIndustryStocks(), - }; -}; diff --git a/src/routes/market-mover/+page.server.ts b/src/routes/market-mover/+page.server.ts new file mode 100644 index 00000000..df5cd05e --- /dev/null +++ b/src/routes/market-mover/+page.server.ts @@ -0,0 +1,38 @@ +export const load = async ({ locals, setHeaders }) => { + const { apiURL, apiKey } = locals; + + const getDailyGainerLoserActive = async () => { + const response = await fetch(apiURL + "/market-movers", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + const getMiniPlotsIndex = async () => { + const response = await fetch(apiURL + "/mini-plots-index", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + setHeaders({ "cache-control": "public, max-age=3000" }); + // Make sure to return a promise + return { + getDailyGainerLoserActive: await getDailyGainerLoserActive(), + getMiniPlotsIndex: await getMiniPlotsIndex(), + }; +}; diff --git a/src/routes/market-mover/+page.ts b/src/routes/market-mover/+page.ts deleted file mode 100644 index daaecfff..00000000 --- a/src/routes/market-mover/+page.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const { apiURL, apiKey } = await parent(); - - const getDailyGainerLoserActive = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDailyGainerLoserActive"); - if (cachedData) { - output = cachedData; - } else { - // make the POST request to the endpoint - const response = await fetch(apiURL + "/market-movers", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getDailyGainerLoserActive"); - } - - return output; - }; - - const getMiniPlotsIndex = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMiniPlotsIndex"); - if (cachedData) { - output = cachedData; - } else { - // make the POST request to the endpoint - const response = await fetch(apiURL + "/mini-plots-index", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getMiniPlotsIndex"); - } - - return output; - }; - - // Make sure to return a promise - return { - getDailyGainerLoserActive: await getDailyGainerLoserActive(), - getMiniPlotsIndex: await getMiniPlotsIndex(), - }; -}; diff --git a/src/routes/market-news/+page.server.ts b/src/routes/market-news/+page.server.ts new file mode 100644 index 00000000..4303e6ad --- /dev/null +++ b/src/routes/market-news/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getMarketNews = async () => { + const { apiURL, apiKey } = locals; + const postData = { newsType: "stock-news" }; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/market-news", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMarketNews: await getMarketNews(), + }; +}; diff --git a/src/routes/market-news/+page.ts b/src/routes/market-news/+page.ts deleted file mode 100644 index b543510b..00000000 --- a/src/routes/market-news/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMarketNews = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMarketNews"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - const postData = { newsType: "stock-news" }; - // make the POST request to the endpoint - const response = await fetch(apiURL + "/market-news", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getMarketNews' - setCache("", output, "getMarketNews"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMarketNews: await getMarketNews(), - }; -}; diff --git a/src/routes/market-news/general/+page.server.ts b/src/routes/market-news/general/+page.server.ts new file mode 100644 index 00000000..4e8917c0 --- /dev/null +++ b/src/routes/market-news/general/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getGeneralNews = async () => { + const { apiURL, apiKey } = locals; + const postData = { newsType: "general-news" }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/market-news", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getGeneralNews: await getGeneralNews(), + }; +}; diff --git a/src/routes/market-news/general/+page.ts b/src/routes/market-news/general/+page.ts deleted file mode 100644 index cd1ad6db..00000000 --- a/src/routes/market-news/general/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getGeneralNews = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getGeneralNews"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - const postData = { newsType: "general-news" }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/market-news", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getGeneralNews' - setCache("", output, "getGeneralNews"); - } - - return output; - }; - - // Make sure to return a promise - return { - getGeneralNews: await getGeneralNews(), - }; -}; diff --git a/src/routes/most-retail-volume/+page.server.ts b/src/routes/most-retail-volume/+page.server.ts new file mode 100644 index 00000000..86e7dc20 --- /dev/null +++ b/src/routes/most-retail-volume/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, setHeaders }) => { + const getMostRetailVolume = async () => { + const { apiKey, apiURL, user } = locals; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/most-retail-volume", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response.json(); + + output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getMostRetailVolume: await getMostRetailVolume(), + }; +}; diff --git a/src/routes/most-retail-volume/+page.ts b/src/routes/most-retail-volume/+page.ts deleted file mode 100644 index ebd79dab..00000000 --- a/src/routes/most-retail-volume/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMostRetailVolume = async () => { - let output; - const { apiKey, apiURL, user } = await parent(); - - const cachedData = getCache("", "getMostRetailVolume"); - if (cachedData) { - output = cachedData; - } else { - // make the POST request to the endpoint - const response = await fetch(apiURL + "/most-retail-volume", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getMostRetailVolume"); - } - - output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getMostRetailVolume: await getMostRetailVolume(), - }; -}; diff --git a/src/routes/most-shorted-stocks/+page.server.ts b/src/routes/most-shorted-stocks/+page.server.ts new file mode 100644 index 00000000..1589ef41 --- /dev/null +++ b/src/routes/most-shorted-stocks/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals, setHeaders }) => { + const getMostShortedStocks = async () => { + const { apiKey, apiURL, user } = locals; + + const response = await fetch(apiURL + "/most-shorted-stocks", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + let output = await response.json(); + output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; + + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getMostShortedStocks: await getMostShortedStocks(), + }; +}; diff --git a/src/routes/most-shorted-stocks/+page.ts b/src/routes/most-shorted-stocks/+page.ts deleted file mode 100644 index 8a6cb205..00000000 --- a/src/routes/most-shorted-stocks/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMostShortedStocks = async () => { - let output; - const { apiKey, apiURL, user } = await parent(); - - const cachedData = getCache("", "getMostShortedStocks"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/most-shorted-stocks", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getMostShortedStocks"); - } - - output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getMostShortedStocks: await getMostShortedStocks(), - }; -}; diff --git a/src/routes/options-flow/+page.server.ts b/src/routes/options-flow/+page.server.ts new file mode 100644 index 00000000..bc735220 --- /dev/null +++ b/src/routes/options-flow/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const { apiURL, apiKey } = locals; + + const getOptionsFlowFeed = async () => { + // make the POST request to the endpoint + const response = await fetch(apiURL + "/options-flow-feed", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getOptionsFlowFeed: await getOptionsFlowFeed(), + }; +}; diff --git a/src/routes/options-flow/+page.ts b/src/routes/options-flow/+page.ts index 88c6d13f..2dc6fe35 100644 --- a/src/routes/options-flow/+page.ts +++ b/src/routes/options-flow/+page.ts @@ -37,30 +37,10 @@ const checkMarketHour = async () => { isBeforeMarketOpenValue || isAfterMarketCloseValue || holidays?.includes(currentDate) - ), + ) ); }; -export const load = async ({ parent }) => { +export const load = async () => { await checkMarketHour(); - const { apiURL, apiKey } = await parent(); - - const getOptionsFlowFeed = async () => { - // make the POST request to the endpoint - const response = await fetch(apiURL + "/options-flow-feed", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - const output = await response.json(); - - return output; - }; - - // Make sure to return a promise - return { - getOptionsFlowFeed: await getOptionsFlowFeed(), - }; }; diff --git a/src/routes/politicians/+page.server.ts b/src/routes/politicians/+page.server.ts new file mode 100644 index 00000000..669d5328 --- /dev/null +++ b/src/routes/politicians/+page.server.ts @@ -0,0 +1,50 @@ +import { getPartyForPoliticians } from "$lib/utils"; + +export const load = async ({ locals }) => { + const getAllPolitician = async () => { + let output; + + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/all-politicians", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + output = await response.json(); + + // Cache the data for this specific tickerID with a specific name 'getAllPolitician' + + output?.forEach((item) => { + let representative = item?.representative || ""; + + representative = representative + ?.replace("Jr", "") + .replace(/Dr./g, "") + .replace(/Dr_/g, ""); + + const fullName = representative + ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") + .trim(); + item.representative = fullName?.replace(/_/g, " "); + }); + + output = output?.map((item) => { + const party = getPartyForPoliticians(item?.representative); + return { + ...item, + party: party, + }; + }); + + return output; + }; + + // Make sure to return a promise + return { + getAllPolitician: await getAllPolitician(), + }; +}; diff --git a/src/routes/politicians/+page.ts b/src/routes/politicians/+page.ts deleted file mode 100644 index 2a7f7dbe..00000000 --- a/src/routes/politicians/+page.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { getCache, setCache } from "$lib/store"; -import { getPartyForPoliticians } from "$lib/utils"; - -export const load = async ({ parent }) => { - const getAllPolitician = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getAllPolitician"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/all-politicians", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getAllPolitician' - - output?.forEach((item) => { - let representative = item?.representative || ""; - - representative = representative - ?.replace("Jr", "") - .replace(/Dr./g, "") - .replace(/Dr_/g, ""); - - const fullName = representative - ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") - .trim(); - item.representative = fullName?.replace(/_/g, " "); - }); - - output = output?.map((item) => { - const party = getPartyForPoliticians(item?.representative); - return { - ...item, - party: party, - }; - }); - - setCache("", output, "getAllPolitician"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAllPolitician: await getAllPolitician(), - }; -}; diff --git a/src/routes/politicians/flow-data/+page.server.ts b/src/routes/politicians/flow-data/+page.server.ts new file mode 100644 index 00000000..7cc189a7 --- /dev/null +++ b/src/routes/politicians/flow-data/+page.server.ts @@ -0,0 +1,50 @@ +import { getPartyForPoliticians } from "$lib/utils"; + +export const load = async ({ locals }) => { + const getPoliticianRSS = async () => { + let output; + + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/congress-rss-feed", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + output = await response.json(); + + // Cache the data for this specific tickerID with a specific name 'getPoliticianRSS' + + output?.forEach((item) => { + let representative = item?.representative || ""; + + representative = representative + ?.replace("Jr", "") + .replace(/Dr./g, "") + .replace(/Dr_/g, ""); + + const fullName = representative + ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") + .trim(); + item.representative = fullName?.replace(/_/g, " "); + }); + + output = output?.map((item) => { + const party = getPartyForPoliticians(item?.representative); + return { + ...item, + party: party, + }; + }); + + return output; + }; + + // Make sure to return a promise + return { + getPoliticianRSS: await getPoliticianRSS(), + }; +}; diff --git a/src/routes/politicians/flow-data/+page.ts b/src/routes/politicians/flow-data/+page.ts deleted file mode 100644 index b8edf94f..00000000 --- a/src/routes/politicians/flow-data/+page.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { getCache, setCache } from "$lib/store"; -import { getPartyForPoliticians } from "$lib/utils"; - -export const load = async ({ parent }) => { - const getPoliticianRSS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getPoliticianRSS"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/congress-rss-feed", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getPoliticianRSS' - - output?.forEach((item) => { - let representative = item?.representative || ""; - - representative = representative - ?.replace("Jr", "") - .replace(/Dr./g, "") - .replace(/Dr_/g, ""); - - const fullName = representative - ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") - .trim(); - item.representative = fullName?.replace(/_/g, " "); - }); - - output = output?.map((item) => { - const party = getPartyForPoliticians(item?.representative); - return { - ...item, - party: party, - }; - }); - - setCache("", output, "getPoliticianRSS"); - } - return output; - }; - - // Make sure to return a promise - return { - getPoliticianRSS: await getPoliticianRSS(), - }; -}; diff --git a/src/routes/price-alert/+page.server.ts b/src/routes/price-alert/+page.server.ts new file mode 100644 index 00000000..967a6e74 --- /dev/null +++ b/src/routes/price-alert/+page.server.ts @@ -0,0 +1,40 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL, fastifyURL, user } = locals; + + const getPriceAlert = async () => { + const postData = { userId: user?.id }; + const response = await fetch(fastifyURL + "/get-price-alert", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(postData), + }); + + let output = (await response.json())?.items; + output = output?.sort((a, b) => a?.symbol?.localeCompare(b?.symbol)); + + return output; + }; + + const getMiniPlotsIndex = async () => { + // make the POST request to the endpoint + const response = await fetch(apiURL + "/mini-plots-index", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMiniPlotsIndex: await getMiniPlotsIndex(), + getPriceAlert: await getPriceAlert(), + }; +}; diff --git a/src/routes/price-alert/+page.svelte b/src/routes/price-alert/+page.svelte index 54fb853a..67bf03ed 100644 --- a/src/routes/price-alert/+page.svelte +++ b/src/routes/price-alert/+page.svelte @@ -83,24 +83,8 @@ rawData?.forEach(({ symbol, priceData, changesPercentage, previousClose }) => { }); let isLoaded = false; -let priceAlertList = []; +let priceAlertList = data?.getPriceAlert; - - -async function getPriceAlert() -{ - const postData = {'userId': data?.user?.id} - const response = await fetch(data?.fastifyURL+'/get-price-alert', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(postData) -}); - - priceAlertList = (await response.json())?.items; - priceAlertList= priceAlertList?.sort((a, b) => a?.symbol?.localeCompare(b?.symbol)); -} @@ -164,11 +148,7 @@ async function handleDelete() { onMount( async () => { -if (data?.user) -{ - await getPriceAlert() -} isLoaded = true; diff --git a/src/routes/price-alert/+page.ts b/src/routes/price-alert/+page.ts deleted file mode 100644 index 94da79e5..00000000 --- a/src/routes/price-alert/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMiniPlotsIndex = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMiniPlotsIndex"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/mini-plots-index", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getMiniPlotsIndex"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMiniPlotsIndex: await getMiniPlotsIndex(), - }; -}; diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts index b8ac473b..64001e3d 100644 --- a/src/routes/sitemap.xml/+server.ts +++ b/src/routes/sitemap.xml/+server.ts @@ -1,7 +1,3 @@ -export const config = { - runtime: "nodejs20.x", -}; - const pages = [ { title: "/" }, { title: "/cramer-tracker" }, @@ -133,7 +129,7 @@ const sitemap = ( posts, articles, stocks, - pages, + pages ) => ` ${website}${page.title} - `, + ` ) .join("")} ${stocks @@ -174,7 +170,7 @@ const sitemap = ( ${website}/blog/article/${article.id} - `, + ` ) .join("")} ${posts @@ -183,7 +179,7 @@ const sitemap = ( ${website}/community/post/${post.id} - `, + ` ) .join("")} `; diff --git a/src/routes/stock-splits-calendar/+page.server.ts b/src/routes/stock-splits-calendar/+page.server.ts new file mode 100644 index 00000000..34f17ac4 --- /dev/null +++ b/src/routes/stock-splits-calendar/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals, setHeaders }) => { + const getStockSplitsCalendar = async () => { + const { apiKey, apiURL } = locals; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-splits-calendar", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + setHeaders({ "cache-control": "public, max-age=3000" }); + + return output; + }; + + // Make sure to return a promise + return { + getStockSplitsCalendar: await getStockSplitsCalendar(), + }; +}; diff --git a/src/routes/stock-splits-calendar/+page.ts b/src/routes/stock-splits-calendar/+page.ts deleted file mode 100644 index ed75402f..00000000 --- a/src/routes/stock-splits-calendar/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getStockSplitsCalendar = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getStockSplitsCalendar"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-splits-calendar", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getStockSplitsCalendar' - setCache("", output, "getStockSplitsCalendar"); - } - - return output; - }; - - // Make sure to return a promise - return { - getStockSplitsCalendar: await getStockSplitsCalendar(), - }; -}; diff --git a/src/routes/stocks/+page.server.ts b/src/routes/stocks/+page.server.ts new file mode 100644 index 00000000..258f1b44 --- /dev/null +++ b/src/routes/stocks/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals }) => { + const getStockList = async () => { + const { apiKey, apiURL } = locals; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/all-stock-tickers", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getStockList: await getStockList(), + }; +}; diff --git a/src/routes/stocks/+page.ts b/src/routes/stocks/+page.ts deleted file mode 100644 index 64d177bb..00000000 --- a/src/routes/stocks/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getStockList = async () => { - let output; - // Get cached data for the specific tickerID - const cachedData = getCache("", "getStockList"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/all-stock-tickers", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getStockList' - setCache("", output, "getStockList"); - } - - return output; - }; - - // Make sure to return a promise - return { - getStockList: await getStockList(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/dividends/+page.server.ts b/src/routes/stocks/[tickerID]/dividends/+page.server.ts new file mode 100644 index 00000000..b5f8e493 --- /dev/null +++ b/src/routes/stocks/[tickerID]/dividends/+page.server.ts @@ -0,0 +1,30 @@ +export const load = async ({ params, locals }) => { + const getStockDividend = async () => { + let newsList; + + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-dividend", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + newsList = await response.json(); + + return newsList; + }; + + // Make sure to return a promise + return { + getStockDividend: await getStockDividend(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/dividends/+page.ts b/src/routes/stocks/[tickerID]/dividends/+page.ts deleted file mode 100644 index de31656b..00000000 --- a/src/routes/stocks/[tickerID]/dividends/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getStockDividend = async () => { - let newsList; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getStockDividend"); - if (cachedData) { - newsList = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-dividend", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - newsList = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getStockDividend' - setCache(params.tickerID, newsList, "getStockDividend"); - } - - return newsList; - }; - - // Make sure to return a promise - return { - getStockDividend: await getStockDividend(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/forecast/+page.server.ts b/src/routes/stocks/[tickerID]/forecast/+page.server.ts new file mode 100644 index 00000000..0762cadb --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getAnalystEstimate = async () => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/analyst-estimate", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getAnalystEstimate: await getAnalystEstimate(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/forecast/+page.ts b/src/routes/stocks/[tickerID]/forecast/+page.ts deleted file mode 100644 index 337a6577..00000000 --- a/src/routes/stocks/[tickerID]/forecast/+page.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getAnalystEstimate = async () => { - let output; - - const cachedData = getCache(params.tickerID, "getAnalystEstimate"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/analyst-estimate", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getAnalystEstimate"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAnalystEstimate: await getAnalystEstimate(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/forecast/ai/+page.server.ts b/src/routes/stocks/[tickerID]/forecast/ai/+page.server.ts new file mode 100644 index 00000000..658b0492 --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/ai/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getAnalystTickerHistory = async () => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/analyst-ticker-history", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getAnalystTickerHistory: await getAnalystTickerHistory(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/forecast/ai/+page.ts b/src/routes/stocks/[tickerID]/forecast/ai/+page.ts deleted file mode 100644 index ad22faa2..00000000 --- a/src/routes/stocks/[tickerID]/forecast/ai/+page.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getAnalystTickerHistory = async () => { - let output; - - const cachedData = getCache(params.tickerID, "getAnalystTickerHistory"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/analyst-ticker-history", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getAnalystTickerHistory"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAnalystTickerHistory: await getAnalystTickerHistory(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts b/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts new file mode 100644 index 00000000..ad4c40ff --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ parent, params }) => { + const getAnalystTickerHistory = async () => { + const { apiURL, apiKey } = await parent(); + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/analyst-ticker-history", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getAnalystTickerHistory: await getAnalystTickerHistory(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts b/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts deleted file mode 100644 index ad22faa2..00000000 --- a/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getAnalystTickerHistory = async () => { - let output; - - const cachedData = getCache(params.tickerID, "getAnalystTickerHistory"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/analyst-ticker-history", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getAnalystTickerHistory"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAnalystTickerHistory: await getAnalystTickerHistory(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/insider/+page.server.ts b/src/routes/stocks/[tickerID]/insider/+page.server.ts new file mode 100644 index 00000000..e09eb86b --- /dev/null +++ b/src/routes/stocks/[tickerID]/insider/+page.server.ts @@ -0,0 +1,112 @@ +const transactionTypeMap = { + "P-Purchase": "Bought", + "A-Award": "Grant", + "D-Return": "Grant", + "G-Gift": "Grant", + "S-Sale": "Sold", + "M-Exempt": "Exercise", + "X-InTheMoney": "Exercise", + "C-Conversion": "Exercise", + "F-InKind": "Sold", + "J-Other": (item) => { + if (item.acquistionOrDisposition === "D") { + return "Sold"; + } else if (item.acquistionOrDisposition === "A") { + return "Bought"; + } else { + return "Other"; + } + }, + "": "n/a", +}; + +export const load = async ({ locals, params }) => { + const { apiURL, apiKey } = locals; + + const getInsiderTrading = async () => { + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/insider-trading", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + let output = await response.json(); + + output = output?.map((item) => ({ + ...item, + transactionType: + typeof transactionTypeMap[item?.transactionType] === "function" + ? transactionTypeMap[item?.transactionType](item) + : transactionTypeMap[item?.transactionType] || "n/a", + })); + + return output; + }; + + const getInsiderTradingStatistics = async () => { + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/insider-trading-statistics", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response?.json(); + + return output; + }; + + async function historicalPrice() { + const postData = { + ticker: params.tickerID, + timePeriod: "max", + }; + + const response = await fetch(apiURL + "/historical-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = (await response?.json()) ?? []; + + //Adding this would create a bug hence I cant use the historicalPrice endpoint such as in +page.svelte but rather need to call + // it again without modification. + /* + output= (data) => map(({ time, open, high, low, close }) => ({ + time: Date.parse(time), + open, + high, + low, + close + })); + */ + + return output; + } + + // Make sure to return a promise + return { + getInsiderTrading: await getInsiderTrading(), + getInsiderTradingStatistics: await getInsiderTradingStatistics(), + getHistoricalPrice: await historicalPrice(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/insider/+page.ts b/src/routes/stocks/[tickerID]/insider/+page.ts deleted file mode 100644 index 41fcceb3..00000000 --- a/src/routes/stocks/[tickerID]/insider/+page.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -const transactionTypeMap = { - "P-Purchase": "Bought", - "A-Award": "Grant", - "D-Return": "Grant", - "G-Gift": "Grant", - "S-Sale": "Sold", - "M-Exempt": "Exercise", - "X-InTheMoney": "Exercise", - "C-Conversion": "Exercise", - "F-InKind": "Sold", - "J-Other": (item) => { - if (item.acquistionOrDisposition === "D") { - return "Sold"; - } else if (item.acquistionOrDisposition === "A") { - return "Bought"; - } else { - return "Other"; - } - }, - "": "n/a", -}; - -export const load = async ({ parent, params }) => { - const { apiURL, apiKey } = await parent(); - - const getInsiderTrading = async () => { - let output; - - const cachedData = getCache(params.tickerID, "getInsiderTrading"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/insider-trading", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - output = output?.map((item) => ({ - ...item, - transactionType: - typeof transactionTypeMap[item?.transactionType] === "function" - ? transactionTypeMap[item?.transactionType](item) - : transactionTypeMap[item?.transactionType] || "n/a", - })); - - setCache(params.tickerID, output, "getInsiderTrading"); - } - - return output; - }; - - const getInsiderTradingStatistics = async () => { - let output; - - const cachedData = getCache(params.tickerID, "getInsiderTradingStatistics"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/insider-trading-statistics", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response?.json(); - - setCache(params.tickerID, output, "getInsiderTradingStatistics"); - } - - return output; - }; - - async function historicalPrice() { - let output; - - const cachedData = getCache(params.tickerID, "historicalPrice" + "insider"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - timePeriod: "max", - }; - - const response = await fetch(apiURL + "/historical-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = (await response?.json()) ?? []; - - //Adding this would create a bug hence I cant use the historicalPrice endpoint such as in +page.svelte but rather need to call - // it again without modification. - /* - output= (data) => map(({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close - })); - */ - - setCache(params.tickerID, output, "historicalPrice" + "insider"); - } - - return output; - } - - // Make sure to return a promise - return { - getInsiderTrading: await getInsiderTrading(), - getInsiderTradingStatistics: await getInsiderTradingStatistics(), - getHistoricalPrice: await historicalPrice(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/insider/congress-trading/+page.server.ts b/src/routes/stocks/[tickerID]/insider/congress-trading/+page.server.ts new file mode 100644 index 00000000..5d81fa27 --- /dev/null +++ b/src/routes/stocks/[tickerID]/insider/congress-trading/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getSenateTrading = async () => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/congress-trading-ticker", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getSenateTrading: await getSenateTrading(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/insider/congress-trading/+page.ts b/src/routes/stocks/[tickerID]/insider/congress-trading/+page.ts deleted file mode 100644 index d3e45836..00000000 --- a/src/routes/stocks/[tickerID]/insider/congress-trading/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getSenateTrading = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getSenateTrading"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/congress-trading-ticker", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getSenateTrading' - setCache(params.tickerID, output, "getSenateTrading"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSenateTrading: await getSenateTrading(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/insider/transcripts/+page.server.ts b/src/routes/stocks/[tickerID]/insider/transcripts/+page.server.ts new file mode 100644 index 00000000..1925869d --- /dev/null +++ b/src/routes/stocks/[tickerID]/insider/transcripts/+page.server.ts @@ -0,0 +1,38 @@ +const now = new Date(); +const year = now?.getFullYear()?.toString(); +const quarter = (Math.floor(now?.getMonth() / 3) + 1)?.toString(); + +export const load = async ({ locals, params }) => { + const getTranscripts = async () => { + let output; + + const { apiKey, apiURL } = locals; + + const postData = { + ticker: params.tickerID, + quarter: quarter, + year: year, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/earnings-call-transcripts", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getTranscripts: await getTranscripts(), + quarter, + year, + }; +}; diff --git a/src/routes/stocks/[tickerID]/insider/transcripts/+page.ts b/src/routes/stocks/[tickerID]/insider/transcripts/+page.ts deleted file mode 100644 index 1a2ab21e..00000000 --- a/src/routes/stocks/[tickerID]/insider/transcripts/+page.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -const now = new Date(); -const year = now?.getFullYear()?.toString(); -const quarter = (Math.floor(now?.getMonth() / 3) + 1)?.toString(); - -export const load = async ({ parent, params }) => { - const getTranscripts = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache( - `${params.tickerID}-Q-1-2024`, - "getTranscripts", - ); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { - ticker: params.tickerID, - quarter: quarter, - year: year, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/earnings-call-transcripts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getTranscripts' - setCache( - `${params.tickerID}-Q-${quarter}-${year}`, - output, - "getTranscripts", - ); - } - - return output; - }; - - // Make sure to return a promise - return { - getTranscripts: await getTranscripts(), - quarter, - year, - }; -}; diff --git a/src/routes/stocks/[tickerID]/news/+page.server.ts b/src/routes/stocks/[tickerID]/news/+page.server.ts new file mode 100644 index 00000000..57c7a85d --- /dev/null +++ b/src/routes/stocks/[tickerID]/news/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getStockNews = async () => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-news", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getStockNews: await getStockNews(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/news/+page.svelte b/src/routes/stocks/[tickerID]/news/+page.svelte index 58f0e90e..420149e2 100644 --- a/src/routes/stocks/[tickerID]/news/+page.svelte +++ b/src/routes/stocks/[tickerID]/news/+page.svelte @@ -91,10 +91,10 @@ function loadMoreData() {
-
-
-
-
+
+
+
+

News

diff --git a/src/routes/stocks/[tickerID]/news/+page.ts b/src/routes/stocks/[tickerID]/news/+page.ts deleted file mode 100644 index a21f117c..00000000 --- a/src/routes/stocks/[tickerID]/news/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getStockNews = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getStockNews"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-news", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getStockNews' - setCache(params.tickerID, output, "getStockNews"); - } - - return output; - }; - - // Make sure to return a promise - return { - getStockNews: await getStockNews(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/options/+page.server.ts b/src/routes/stocks/[tickerID]/options/+page.server.ts new file mode 100644 index 00000000..1bb17d33 --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/+page.server.ts @@ -0,0 +1,94 @@ +export const load = async ({ locals, params }) => { + const getOptionsPlotData = async () => { + const postData = { + ticker: params.tickerID, + }; + + const response = await fetch(locals?.apiURL + "/options-plot-ticker", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": locals?.apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getOptionsHistoricalData = async () => { + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch( + locals?.apiURL + "/options-historical-data-ticker", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": locals?.apiKey, + }, + body: JSON.stringify(postData), + } + ); + + const output = await response.json(); + + return output; + }; + + const getOptionsChainData = async () => { + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch( + locals?.apiURL + "/options-chain-data-ticker", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": locals?.apiKey, + }, + body: JSON.stringify(postData), + } + ); + + const output = await response.json(); + + return output; + }; + + const getOptionsGexData = async () => { + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(locals?.apiURL + "/options-gex-ticker", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": locals?.apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getOptionsPlotData: await getOptionsPlotData(), + getOptionsHistoricalData: await getOptionsHistoricalData(), + getOptionsChainData: await getOptionsChainData(), + getOptionsGexData: await getOptionsGexData(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/options/+page.ts b/src/routes/stocks/[tickerID]/options/+page.ts deleted file mode 100644 index 10ff6ef1..00000000 --- a/src/routes/stocks/[tickerID]/options/+page.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const { apiKey, apiURL } = await parent(); - - const getOptionsPlotData = async () => { - const cachedData = getCache(params.tickerID, "getOptionsPlotData"); - if (cachedData) { - return cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - const response = await fetch(apiURL + "/options-plot-ticker", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - const output = await response.json(); - - setCache(params.tickerID, output, "getOptionsPlotData"); - return output; - } - }; - - const getOptionsHistoricalData = async () => { - let output; - const cachedData = getCache(params.tickerID, "getOptionsHistoricalData"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/options-historical-data-ticker", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getOptionsHistoricalData"); - } - - return output; - }; - - const getOptionsChainData = async () => { - let output; - const cachedData = getCache(params.tickerID, "getOptionsChainData"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/options-chain-data-ticker", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getOptionsChainData"); - } - - return output; - }; - - const getOptionsGexData = async () => { - let output; - const cachedData = getCache(params.tickerID, "getOptionsGexData"); - if (cachedData) { - output = cachedData; - } else { - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/options-gex-ticker", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache(params.tickerID, output, "getOptionsGexData"); - } - - return output; - }; - - // Make sure to return a promise - return { - getOptionsPlotData: await getOptionsPlotData(), - getOptionsHistoricalData: await getOptionsHistoricalData(), - getOptionsChainData: await getOptionsChainData(), - getOptionsGexData: await getOptionsGexData(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/+page.server.ts b/src/routes/stocks/[tickerID]/stats/+page.server.ts index 6614cf1e..1999743a 100644 --- a/src/routes/stocks/[tickerID]/stats/+page.server.ts +++ b/src/routes/stocks/[tickerID]/stats/+page.server.ts @@ -2,11 +2,40 @@ import { error, fail, redirect } from "@sveltejs/kit"; import { validateData } from "$lib/utils"; import { loginUserSchema, registerUserSchema } from "$lib/schemas"; +export const load = async ({ locals, params }) => { + const getQuantStats = async () => { + const { apiKey, apiURL } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/get-quant-stats", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getQuantStats: await getQuantStats(), + }; +}; + export const actions = { login: async ({ request, locals }) => { const { formData, errors } = await validateData( await request.formData(), - loginUserSchema, + loginUserSchema ); if (errors) { @@ -40,7 +69,7 @@ export const actions = { register: async ({ locals, request }) => { const { formData, errors } = await validateData( await request.formData(), - registerUserSchema, + registerUserSchema ); if (errors) { @@ -94,7 +123,7 @@ await locals.pb?.collection('users').update( const redirectURL = `${url.origin}/oauth`; const targetItem = authMethods.authProviders?.findIndex( - (item) => item?.name === providerSelected, + (item) => item?.name === providerSelected ); //console.log("==================") //console.log(authMethods.authProviders) diff --git a/src/routes/stocks/[tickerID]/stats/+page.ts b/src/routes/stocks/[tickerID]/stats/+page.ts deleted file mode 100644 index 30eceee2..00000000 --- a/src/routes/stocks/[tickerID]/stats/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getQuantStats = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getQuantStats"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/get-quant-stats", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getQuantStats' - setCache(params.tickerID, output, "getQuantStats"); - } - - return output; - }; - - // Make sure to return a promise - return { - getQuantStats: await getQuantStats(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.server.ts b/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.server.ts new file mode 100644 index 00000000..c3f14f97 --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.server.ts @@ -0,0 +1,29 @@ +import { getCache, setCache } from "$lib/store"; + +export const load = async ({ locals, params }) => { + const getBalanceSheetStatement = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-balance-sheet", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getBalanceSheetStatement: await getBalanceSheetStatement(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.ts b/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.ts deleted file mode 100644 index 936aeac1..00000000 --- a/src/routes/stocks/[tickerID]/stats/balance-sheet/+page.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getBalanceSheetStatement = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getBalanceSheetStatement"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-balance-sheet", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getBalanceSheetStatement' - setCache(params.tickerID, output, "getBalanceSheetStatement"); - } - - return output; - }; - - // Make sure to return a promise - return { - getBalanceSheetStatement: await getBalanceSheetStatement(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/cash-flow/+page.server.ts b/src/routes/stocks/[tickerID]/stats/cash-flow/+page.server.ts new file mode 100644 index 00000000..3a9a0b90 --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/cash-flow/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getCashFlowStatement = async () => { + const { apiKey, apiURL } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-cash-flow", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getCashFlowStatement: await getCashFlowStatement(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/cash-flow/+page.ts b/src/routes/stocks/[tickerID]/stats/cash-flow/+page.ts deleted file mode 100644 index da6ac747..00000000 --- a/src/routes/stocks/[tickerID]/stats/cash-flow/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getCashFlowStatement = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getCashFlowStatement"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-cash-flow", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getCashFlowStatement' - setCache(params.tickerID, output, "getCashFlowStatement"); - } - - return output; - }; - - // Make sure to return a promise - return { - getCashFlowStatement: await getCashFlowStatement(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/employees/+page.server.ts b/src/routes/stocks/[tickerID]/stats/employees/+page.server.ts new file mode 100644 index 00000000..86a6987f --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/employees/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getHistoryEmployee = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/history-employees", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getHistoryEmployee: await getHistoryEmployee(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/employees/+page.ts b/src/routes/stocks/[tickerID]/stats/employees/+page.ts deleted file mode 100644 index 452b7bb0..00000000 --- a/src/routes/stocks/[tickerID]/stats/employees/+page.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getHistoryEmployee = async () => { - let output; - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getHistoryEmployee"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/history-employees", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoryEmployee' - setCache(params.tickerID, output, "getHistoryEmployee"); - } - - return output; - }; - - // Make sure to return a promise - return { - getHistoryEmployee: await getHistoryEmployee(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/income/+page.server.ts b/src/routes/stocks/[tickerID]/stats/income/+page.server.ts new file mode 100644 index 00000000..6960a6cc --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/income/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getIncomeStatement = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-income", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getIncomeStatement: await getIncomeStatement(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/income/+page.ts b/src/routes/stocks/[tickerID]/stats/income/+page.ts deleted file mode 100644 index bda1d5fd..00000000 --- a/src/routes/stocks/[tickerID]/stats/income/+page.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getIncomeStatement = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getIncomeStatement"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-income", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getIncomeStatement' - setCache(params.tickerID, output, "getIncomeStatement"); - } - - return output; - }; - - // Make sure to return a promise - return { - getIncomeStatement: await getIncomeStatement(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/market-cap/+page.server.ts b/src/routes/stocks/[tickerID]/stats/market-cap/+page.server.ts new file mode 100644 index 00000000..8696411e --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/market-cap/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getHistoricalMarketCap = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/historical-market-cap", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getHistoricalMarketCap: await getHistoricalMarketCap(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte index e9dccfd9..51790f3f 100644 --- a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte @@ -249,6 +249,7 @@ async function plotData() type: 'line', areaStyle: {opacity: 0.2}, smooth: true, + symbol: 'none', }, ], tooltip: { diff --git a/src/routes/stocks/[tickerID]/stats/market-cap/+page.ts b/src/routes/stocks/[tickerID]/stats/market-cap/+page.ts deleted file mode 100644 index 44816223..00000000 --- a/src/routes/stocks/[tickerID]/stats/market-cap/+page.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getHistoricalMarketCap = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getHistoricalMarketCap"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/historical-market-cap", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalMarketCap' - setCache(params.tickerID, output, "getHistoricalMarketCap"); - } - - return output; - }; - - // Make sure to return a promise - return { - getHistoricalMarketCap: await getHistoricalMarketCap(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/stats/ratios/+page.server.ts b/src/routes/stocks/[tickerID]/stats/ratios/+page.server.ts new file mode 100644 index 00000000..4fc545f7 --- /dev/null +++ b/src/routes/stocks/[tickerID]/stats/ratios/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getRatiosStatement = async () => { + const { apiKey, apiURL } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/stock-ratios", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getRatiosStatement: await getRatiosStatement(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/ratios/+page.ts b/src/routes/stocks/[tickerID]/stats/ratios/+page.ts deleted file mode 100644 index 1b2e02ac..00000000 --- a/src/routes/stocks/[tickerID]/stats/ratios/+page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getRatiosStatement = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getRatiosStatement"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/stock-ratios", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getRatiosStatement' - setCache(params.tickerID, output, "getRatiosStatement"); - } - - return output; - }; - - // Make sure to return a promise - return { - getRatiosStatement: await getRatiosStatement(), - }; -};