poe-api-manager
Version:
poe.ninja and poe.watch API
35 lines (34 loc) • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fetchData_1 = __importDefault(require("../fetch/fetchData"));
const propertyFilter_1 = __importDefault(require("../../../mainfunctions/propertyFilter"));
/**
* Fetches data from the specified league, type, and typeName.
*
* @param league - The name of the league to fetch data from.
* @param typeName - The name of the type to fetch data for.
* @param type - The type of data to fetch.
* @param requestedProperties - Optional. An array of properties to filter the fetched data by.
* @returns A promise that resolves to an array of objects containing the fetched data.
* @throws If there is an error fetching the data.
*/
async function getData(league, typeName, type, requestedProperties) {
try {
const fetchedData = await (0, fetchData_1.default)(league, typeName, type);
//if requestedProperties use filterProperties to filter fetchedData
if (requestedProperties) {
const result = (0, propertyFilter_1.default)(fetchedData, requestedProperties);
return result;
}
else {
return fetchedData;
}
}
catch (error) {
throw new Error(`Type:${type} Error fetching data: ${error.message}`);
}
}
exports.default = getData;