migrate to page.server.ts

This commit is contained in:
MuslemRahimi 2024-09-20 15:41:59 +02:00
parent 0881ea2b88
commit ed01d69f44
28 changed files with 485 additions and 631 deletions

View File

@ -68,8 +68,7 @@ $: {
{:else}
during market hours.
{/if}
<br>
Analysts project revenue of <strong>{abbreviateNumber(rawData?.revenueEst,true)}</strong>, reflecting a
<br>Analysts project revenue of <strong>{abbreviateNumber(rawData?.revenueEst,true)}</strong>, reflecting a
<strong>{revenueRatio}%</strong> YoY {revenueRatio > 0 ? 'growth' : revenueRatio < 0 ? 'shrinking' : ''} and earnings per share of
<strong>{rawData?.epsEst}</strong>, making a <strong>{epsRatio}%</strong> {epsRatio > 0 ? 'increase' : epsRatio < 0 ? 'decrease' : ''} YoY.
</div>

View File

@ -0,0 +1,23 @@
export const load = async ({ locals }) => {
const getCryptoList = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/all-crypto-tickers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = (await response.json())?.sort(
(a, b) => b?.marketCap - a?.marketCap
);
return output;
};
// Make sure to return a promise
return {
getCryptoList: await getCryptoList(),
};
};

View File

@ -2,38 +2,20 @@
import { goto } from '$app/navigation';
import { numberOfUnreadNotification, screenWidth } from '$lib/store';
import { abbreviateNumber } from '$lib/utils';
import { page } from '$app/stores';
import logo from '$lib/images/box_logo.png';
import ArrowLogo from "lucide-svelte/icons/move-up-right";
export let data;
let charNumber =50;
let notDestroyed = true;
let rawData = data?.getCryptoList;
let symbolList = rawData //rawData?.slice(0,30);
$: {
if($screenWidth < 640)
{
charNumber = 20;
}
else {
charNumber =50;
}
}
$: {
if ($page.url.pathname !== '/crypto') {
notDestroyed = false;
}
}
$: charNumber = $screenWidth < 640 ? 15 : 40;
</script>
@ -62,18 +44,25 @@ $: {
</svelte:head>
<section class="w-full max-w-4xl overflow-hidden m-auto min-h-screen pt-5 pb-40">
<!--
<div class="text-sm breadcrumbs ml-4">
<ul>
<li><a href="/" class="text-gray-300">Home</a></li>
<li><a class="text-gray-300">All Crypto Symbols</a></li>
</ul>
</div>
-->
<section class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden min-h-screen pt-5 pb-40 lg:px-3">
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
<ul>
<li><a href="/" class="text-gray-300">Home</a></li>
<li class="text-gray-300">All Cryptos</li>
</ul>
</div>
<div class="w-full overflow-hidden m-auto mt-5">
<div class="sm:p-0 flex justify-center w-full m-auto overflow-hidden ">
<div class="relative flex justify-center items-start overflow-hidden w-full">
<div class="w-full max-w-4xl m-auto sm:bg-[#27272A] sm:rounded-xl h-auto pl-10 pr-10 pt-5 sm:pb-10 sm:pt-10 mt-3 mb-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-10">
<main class="w-full lg:w-3/4 lg:pr-5">
<div class="w-full m-auto sm:bg-[#27272A] sm:rounded-xl h-auto pl-10 pr-10 pt-5 sm:pb-10 sm:pt-10 mt-3 mb-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-10">
<!-- Start Column -->
<div>
@ -196,11 +185,65 @@ $: {
</div>
</div>
<!--<InfiniteLoading on:infinite={infiniteHandler} />-->
</main>
<aside class="hidden lg:block relative fixed w-1/4 ml-4">
{#if data?.user?.tier !== 'Pro' || data?.user?.freeTrial}
<div on:click={() => goto('/pricing')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer">
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0">
<div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Pro Subscription 🔥
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0"/>
</div>
<span class="text-white p-3 ml-3 mr-3">
Upgrade now for unlimited access to all data and tools
</span>
</div>
</div>
{/if}
<div on:click={() => goto('/analysts')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer">
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0">
<div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Top Analyst 📊
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0"/>
</div>
<span class="text-white p-3 ml-3 mr-3">
Get the latest top Wall Street analyst ratings
</span>
</div>
</div>
<div on:click={() => goto('/analysts/top-stocks')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer">
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0">
<div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Top Stocks Picks ⭐
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0"/>
</div>
<span class="text-white p-3 ml-3 mr-3">
Get the latest top Wall Street analyst ratings.
</span>
</div>
</div>
</aside>
</div>
</div>
</div>
</section>
</section>

View File

@ -1,36 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getCryptoList = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getCryptoList");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/all-crypto-tickers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = (await response.json())?.sort(
(a, b) => b?.marketCap - a?.marketCap,
);
// Cache the data for this specific tickerID with a specific name 'getCryptoList'
setCache("", output, "getCryptoList");
}
return output;
};
// Make sure to return a promise
return {
getCryptoList: await getCryptoList(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getSenateTrading = async () => {
const { apiKey, apiURL } = 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(),
};
};

View File

@ -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 { apiKey, apiURL } = 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(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getStockNews = async () => {
const { apiKey, apiURL } = 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(),
};
};

View File

@ -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 { apiKey, apiURL } = 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(),
};
};

View File

@ -0,0 +1,27 @@
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(),
};
};

View File

@ -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");
}
console.log(output);
return output;
};
// Make sure to return a promise
return {
getQuantStats: await getQuantStats(),
};
};

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, params }) => {
const getSenateTrading = async () => {
const { apiKey, apiURL } = 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;
};
return {
getSenateTrading: await getSenateTrading(),
};
};

View File

@ -1,40 +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 { apiKey, apiURL } = 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(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getStockDividend = async () => {
const { apiKey, apiURL } = 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),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getStockDividend: await getStockDividend(),
};
};

View File

@ -1,40 +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 { apiKey, apiURL } = 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(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getETFHoldings = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/etf-holdings", {
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 {
getETFHoldings: await getETFHoldings(),
};
};

View File

@ -1,40 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getETFHoldings = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getETFHoldings");
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 + "/etf-holdings", {
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 'getETFHoldings'
setCache(params.tickerID, output, "getETFHoldings");
}
return output;
};
// Make sure to return a promise
return {
getETFHoldings: await getETFHoldings(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getStockNews = async () => {
const { apiKey, apiURL } = 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(),
};
};

View File

@ -1,40 +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 { apiKey, apiURL } = 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(),
};
};

View File

@ -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(),
};
};

View File

@ -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(),
};
};

View File

@ -0,0 +1,28 @@
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(),
};
};

View File

@ -1,42 +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");
}
console.log(output);
return output;
};
// Make sure to return a promise
return {
getQuantStats: await getQuantStats(),
};
};

View File

@ -0,0 +1,21 @@
export const load = async ({ locals }) => {
const getAllETFProviders = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/all-etf-providers", {
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 {
getAllETFProviders: await getAllETFProviders(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getAllETFProviders = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getAllETFProviders");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/all-etf-providers", {
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 'getAllETFProviders'
setCache("", output, "getAllETFProviders");
}
return output;
};
// Make sure to return a promise
return {
getAllETFProviders: await getAllETFProviders(),
};
};

View File

@ -0,0 +1,29 @@
export const load = async ({ params, locals }) => {
const getProviderName = async () => {
return params.slug;
};
const getETFProviderData = async () => {
const { apiKey, apiURL } = locals;
const postData = { etfProvider: params.slug };
const response = await fetch(apiURL + "/etf-provider", {
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 {
getETFProviderData: await getETFProviderData(),
getProviderName: await getProviderName(),
};
};

View File

@ -1,42 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ params, parent }) => {
const getProviderName = async () => {
return params.slug;
};
const getETFProviderData = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.slug, "getETFProviderData");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { etfProvider: params.slug };
const response = await fetch(apiURL + "/etf-provider", {
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 'getETFProviderData'
setCache(params.slug, output, "getETFProviderData");
}
return output;
};
// Make sure to return a promise
return {
getETFProviderData: await getETFProviderData(),
getProviderName: await getProviderName(),
};
};

View File

@ -0,0 +1,22 @@
export const load = async ({ locals }) => {
const getETFNewLaunches = async () => {
const { apiKey, apiURL } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/etf-new-launches", {
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 {
getETFNewLaunches: await getETFNewLaunches(),
};
};

View File

@ -1,36 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getETFNewLaunches = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getETFNewLaunches");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/etf-new-launches", {
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 'getETFNewLaunches'
setCache("", output, "getETFNewLaunches");
}
return output;
};
// Make sure to return a promise
return {
getETFNewLaunches: await getETFNewLaunches(),
};
};