frontend/src/routes/analysts/+page.ts
2024-07-30 01:00:35 +02:00

37 lines
804 B
TypeScript

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