feat/institutions_data_from_api
#4
Merged
rbantu
merged 8 commits from feat/institutions_data_from_api
into master
7 months ago
6 changed files with 129 additions and 58 deletions
-
8src/app/api/auth.js
-
51src/app/api/fetchInstutions.js
-
4src/app/auth/authClient.js
-
10src/app/config/constants.js
-
37src/app/screens/RegisterScreen.js
-
77src/app/screens/UpdateUserInfoScreen.js
@ -0,0 +1,51 @@ |
|||||
|
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; |
||||
|
}); |
||||
|
} |
@ -1,11 +1,11 @@ |
|||||
import { create } from "apisauce"; |
import { create } from "apisauce"; |
||||
|
|
||||
const authClient = create({ |
const authClient = create({ |
||||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users", |
|
||||
|
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users", |
||||
}); |
}); |
||||
|
|
||||
const authChangePswdClient = create({ |
const authChangePswdClient = create({ |
||||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/forgotpasswords" |
|
||||
|
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/forgotpasswords" |
||||
}) |
}) |
||||
|
|
||||
export { authClient, authChangePswdClient}; |
export { authClient, authChangePswdClient}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue