forked from cemaden-educacao/WPD-MobileApp
Browse Source
Merge pull request 'feat/institutions_data_from_api' (#4) from feat/institutions_data_from_api into master
Merge pull request 'feat/institutions_data_from_api' (#4) from feat/institutions_data_from_api into master
Reviewed-on: https://git.quijaua.com.br/cemaden-educacao/WPD-MobileApp/pulls/4master
rbantu
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"; |
|||
|
|||
const authClient = create({ |
|||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users", |
|||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users", |
|||
}); |
|||
|
|||
const authChangePswdClient = create({ |
|||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/forgotpasswords" |
|||
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/forgotpasswords" |
|||
}) |
|||
|
|||
export { authClient, authChangePswdClient}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue