update
This commit is contained in:
parent
164f33142a
commit
0bdf5b1bec
@ -1,37 +0,0 @@
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
|
||||
export const load = async ({locals}) => {
|
||||
|
||||
const userRegion = locals.region?.split("::")[0];
|
||||
|
||||
let apiURL;
|
||||
|
||||
if (usRegion?.includes(userRegion)) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
};
|
||||
|
||||
const getTopAnalyst = async () => {
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/top-analysts', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
let output = await response.json();
|
||||
|
||||
output = locals?.user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output;
|
||||
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
// Make sure to return a promise
|
||||
return {
|
||||
getTopAnalyst: await getTopAnalyst()
|
||||
};
|
||||
};
|
||||
50
src/routes/analysts/+page.ts
Normal file
50
src/routes/analysts/+page.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { userRegion, getCache, setCache } from '$lib/store';
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let apiURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
|
||||
if (usRegion.includes(value)) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
export const load = async ( { parent } ) => {
|
||||
|
||||
const getTopAnalyst = async () => {
|
||||
const data = 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',
|
||||
},
|
||||
});
|
||||
|
||||
output = await response?.json();
|
||||
setCache('', output, 'getTopAnalyst');
|
||||
}
|
||||
|
||||
output = data?.user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output;
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
// Make sure to return a promise
|
||||
return {
|
||||
getTopAnalyst: await getTopAnalyst()
|
||||
};
|
||||
};
|
||||
@ -19,7 +19,6 @@ userRegion.subscribe(value => {
|
||||
export const load = async () => {
|
||||
const getStockList = async () => {
|
||||
let output;
|
||||
|
||||
// Get cached data for the specific tickerID
|
||||
const cachedData = getCache('', 'getStockList');
|
||||
if (cachedData) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user