experimental test

This commit is contained in:
MuslemRahimi 2025-02-22 21:13:20 +01:00
parent 000a21ae76
commit 0af0ec1ee5

View File

@ -77,44 +77,29 @@ export const load = async ({ params, locals }) => {
const { apiURL, apiKey, pb, user } = locals; const { apiURL, apiKey, pb, user } = locals;
const { tickerID } = params; const { tickerID } = params;
const endpoints = [
"/stockdeck",
"/analyst-summary-rating",
"/stock-quote",
"/pre-post-quote",
"/wiim",
"/one-day-price",
"/next-earnings",
"/earnings-surprise",
"/stock-news",
];
if (!tickerID) { if (!tickerID) {
return { error: 'Invalid ticker ID' }; return { error: 'Invalid ticker ID' };
} }
try { try {
const [ // Fetch combined stock data from the '/stock-data' endpoint
getStockDeck, const getStockData = await fetchData(apiURL, apiKey, "/stock-data", tickerID);
getAnalystSummary,
getStockQuote,
getPrePostQuote,
getWhyPriceMoved,
getOneDayPrice,
getNextEarnings,
getEarningsSurprise,
getNews,
getUserWatchlist,
] = await Promise.all([
...endpoints.map((endpoint) =>
fetchData(apiURL, apiKey, endpoint, tickerID).catch(error => ({ error: error.message }))
),
fetchWatchlist(pb, user?.id).catch(() => [])
]);
if (!getStockDeck || getStockDeck.error) { // Destructure the returned object to assign friendly names
return { error: 'Failed to fetch stock data' }; const {
} '/stockdeck': getStockDeck,
'/analyst-summary-rating': getAnalystSummary,
'/stock-quote': getStockQuote,
'/pre-post-quote': getPrePostQuote,
'/wiim': getWhyPriceMoved,
'/one-day-price': getOneDayPrice,
'/next-earnings': getNextEarnings,
'/earnings-surprise': getEarningsSurprise,
'/stock-news': getNews,
} = getStockData;
// Optionally, you can still fetch additional data like the watchlist:
const getUserWatchlist = await fetchWatchlist(pb, user?.id).catch(() => []);
return { return {
getStockDeck, getStockDeck,
@ -128,7 +113,7 @@ export const load = async ({ params, locals }) => {
getNews, getNews,
getUserWatchlist, getUserWatchlist,
companyName: cleanString(getStockDeck?.companyName), companyName: cleanString(getStockDeck?.companyName),
getParams: params.tickerID, getParams: tickerID,
}; };
} catch (error) { } catch (error) {
return { error: 'Failed to load stock data' }; return { error: 'Failed to load stock data' };