Skip to content

Commit

Permalink
sort predicates file
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Feb 23, 2024
1 parent 7383721 commit 58cab98
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/controllers/cron/update_local_smartapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ const getServerFromSpec = spec => {
return sorted_servers[0].url;
};

const sortObject = object => {
if (Array.isArray(object)) {
return object.sort();
}

// apparently typeof null is object
if (typeof object === 'object' && object !== null) {
return Object.keys(object).sort().reduce((acc, key) => {
acc[key] = sortObject(object[key]);
return acc;
}, {});
}

return object;
}

const getTRAPIWithPredicatesEndpoint = specs => {
const trapi = [];
let excluded_list = config.EXCLUDE_LIST.map(api => api.id);
Expand Down Expand Up @@ -192,12 +208,13 @@ const getOpsFromEndpoint = async metadata => {

const getOpsFromPredicatesEndpoints = async specs => {
const metadatas = getTRAPIWithPredicatesEndpoint(specs);
metadatas.sort((a, b) => a.association.smartapi.id.localeCompare(b.association.smartapi.id));
let res = [];
debug(`Now caching predicates from ${metadatas.length} TRAPI APIs`);
await Promise.allSettled(metadatas.map(metadata => getOpsFromEndpoint(metadata))).then(results => {
results.map(rec => {
if (rec.status === "fulfilled" && rec.value) {
res.push(rec.value);
res.push(sortObject(rec.value));
}
});
});
Expand Down

0 comments on commit 58cab98

Please sign in to comment.