You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.2 KiB

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, cidade } = institution;
if (!uf) {
uf = "DF";
}
if (!cidade) {
cidade = "Brasília";
}
if (!transformedData[uf]) {
transformedData[uf] = {};
}
if (!transformedData[uf][cidade]) {
transformedData[uf][cidade] = {};
}
if (!transformedData[uf][cidade][type]) {
transformedData[uf][cidade][type] = [];
}
transformedData[uf][cidade][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;
});
}