Browse Source

feat: create institutions fetch

feat/institutions_data_from_api
bobmw 7 months ago
parent
commit
ada022d73f
  1. 43
      src/app/api/fetchInstutions.js

43
src/app/api/fetchInstutions.js

@ -0,0 +1,43 @@
import { create } from "apisauce";
const fetchInstitutions = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/organizations/all",
});
function transformData(institutions) {
const transformedData = {};
institutions.forEach((institution) => {
let { uf, type, name } = institution;
if (!uf) {
uf = "DF";
}
if (!transformedData[uf]) {
transformedData[uf] = {};
}
if (!transformedData[uf][type]) {
transformedData[uf][type] = [];
}
transformedData[uf][type].push({ value: name, label: name });
});
return transformedData;
}
export function getInstitutions() {
return fetchInstitutions.get()
.then((response) => {
if (response.ok) {
return transformData(response.data);
} else {
throw new Error("Falha ao tentar buscar instituicoes no banco de dados");
}
})
.catch((error) => {
throw error;
});
}
Loading…
Cancel
Save