frontend/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts
2024-10-13 10:33:04 +02:00

30 lines
740 B
TypeScript

export const load = async ({ locals, params }) => {
const getAnalystTickerHistory = async () => {
const { apiURL, apiKey, user } = 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),
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getAnalystTickerHistory: await getAnalystTickerHistory(),
};
};