protect endpoints

This commit is contained in:
MuslemRahimi 2024-09-23 01:28:11 +02:00
parent aab619dc21
commit 5eec132117
23 changed files with 473 additions and 761 deletions

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getBasicMaterialsSector = async () => {
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getBasicMaterialsSector: await getBasicMaterialsSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getBasicMaterialsSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getBasicMaterialsSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getBasicMaterialsSector'
setCache("", output, "getBasicMaterialsSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("basic-materials", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("basic-materials", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getBasicMaterialsSector: await getBasicMaterialsSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getCommunicationServicesSector = async () => {
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getCommunicationServicesSector: await getCommunicationServicesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,72 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getCommunicationServicesSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getCommunicationServicesSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getCommunicationServicesSector'
setCache("", output, "getCommunicationServicesSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(
"communication-services",
"getHistoricalSector",
);
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("communication-services", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getCommunicationServicesSector: await getCommunicationServicesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getConsumerCyclicalSector = async () => {
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getConsumerCyclicalSector: await getConsumerCyclicalSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,68 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getConsumerCyclicalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getConsumerCyclicalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getConsumerCyclicalSector'
setCache("", output, "getConsumerCyclicalSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("consumer-cyclical", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("consumer-cyclical", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getConsumerCyclicalSector: await getConsumerCyclicalSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getConsumerDefensiveSector = async () => {
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getConsumerDefensiveSector: await getConsumerDefensiveSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getConsumerDefensiveSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getConsumerDefensiveSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getConsumerDefensiveSector'
setCache("", output, "getConsumerDefensiveSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("consumer-defensive", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("consumer-defensive", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getConsumerDefensiveSector: await getConsumerDefensiveSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getEnergySector = async () => {
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getEnergySector: await getEnergySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getEnergySector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getEnergySector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getEnergySector'
setCache("", output, "getEnergySector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("energy", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("energy", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getEnergySector: await getEnergySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getFinancialSector = async () => {
const postData = { filterList: "financial" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "financial" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getFinancialSector: await getFinancialSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getFinancialSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getFinancialSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "financial" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getFinancialSector'
setCache("", output, "getFinancialSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("financial", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "financial" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("financial", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getFinancialSector: await getFinancialSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getHealthcareSector = async () => {
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getHealthcareSector: await getHealthcareSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getHealthcareSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getHealthcareSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getHealthcareSector'
setCache("", output, "getHealthcareSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("healthcare", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("healthcare", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getHealthcareSector: await getHealthcareSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getIndustrialsSector = async () => {
const postData = { filterList: "industrials" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "industrials" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getIndustrialsSector: await getIndustrialsSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getIndustrialsSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getIndustrialsSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "industrials" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getIndustrialsSector'
setCache("", output, "getIndustrialsSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("industrials", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "industrials" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("industrials", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getIndustrialsSector: await getIndustrialsSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getRealEstateSector = async () => {
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getRealEstateSector: await getRealEstateSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,68 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getRealEstateSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getRealEstateSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getRealEstateSector'
setCache("", output, "getRealEstateSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("real-estate", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("real-estate", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getRealEstateSector: await getRealEstateSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getTechnologySector = async () => {
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getTechnologySector: await getTechnologySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getTechnologySector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getTechnologySector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getTechnologySector'
setCache("", output, "getTechnologySector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("technology", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("technology", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getTechnologySector: await getTechnologySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,43 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getUtilitiesSector = async () => {
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 {
getUtilitiesSector: await getUtilitiesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,69 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getUtilitiesSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getUtilitiesSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/filter-stock-list", {
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 'getUtilitiesSector'
setCache("", output, "getUtilitiesSector");
}
return output;
};
const getHistoricalSector = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("utilities", "getHistoricalSector");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/historical-sector-price", {
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 'getHistoricalSector'
setCache("utilities", output, "getHistoricalSector");
}
return output;
};
// Make sure to return a promise
return {
getUtilitiesSector: await getUtilitiesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -607,7 +607,6 @@ async function historicalPrice(timePeriod: string) {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": data?.apiKey,
},
body: JSON.stringify(postData),
});