leumas-universal-crud-react
Version:
Leumas Universal CRUD to a dynamic Endpoint, Setup your own Dynamic Endpoint and Use Leumas API to send to your MONGO clusters
20 lines (19 loc) • 830 B
JSX
// fetchSchemas.js
/**
* Fetches available schema names from the server.
* @param {function} onSuccess - Callback function to handle success.
* @param {function} onError - Callback function to handle error.
* @param {string} apiEndpoint - API endpoint to fetch schemas.
* @param {array} excludedSchemas - List of schemas to be excluded.
*/
export const fetchSchemas = (onSuccess, onError, apiEndpoint, excludedSchemas) => {
fetch(`${apiEndpoint}/schema`)
.then(res => res.json())
.then(data => {
const filteredSchemas = data
.filter(schema => !excludedSchemas.includes(schema))
.sort((a, b) => a.localeCompare(b)); // Sort schemas alphabetically
onSuccess(filteredSchemas);
})
.catch(error => onError(error));
};