|
|
@ -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; |
|
|
|
}); |
|
|
|
} |