Skip to content
Snippets Groups Projects
Commit e5bc5c90 authored by Lucas Eduardo Schoenfelder's avatar Lucas Eduardo Schoenfelder
Browse files

fetchall async

parent 976a83f3
No related branches found
No related tags found
2 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...
...@@ -191,23 +191,40 @@ export const postRequest = (url, payload, onSuccess, onError) => { ...@@ -191,23 +191,40 @@ export const postRequest = (url, payload, onSuccess, onError) => {
}) })
} }
export const fetchAllRequest = (urls, onSuccess, onError) => { export async function fetchAllRequest (urls, onSuccess, onError) {
Promise.all( urls.map( url => fetch(`${apiUrl}${url}`, { let responses = await Promise.all( urls.map( url => fetch(`${apiUrl}${url}`, {
headers : fetchHeaders() headers : fetchHeaders()
}))).then( (responses) => { })))
for(let res of responses) {
if (res.headers.has('access-token') && res.status !== 304) { console.log(responses)
updateAccessToken(res.headers.get('access-token')) for (let res of responses) {
} if (res.headers.has('access-token') && res.status !== 304) {
updateAccessToken(res.headers.get('access-token'))
} }
return Promise.all(responses.map( (response) => response.json().catch(err => { }
return {};
}))) let data = await Promise.all(responses.map( (response) => response.json().catch(err => {
}).then( (data) => { return {};
onSuccess(data) })))
}).catch((error) => {
onError(error) onSuccess(data)
})
// await Promise.all( urls.map( url => fetch(`${apiUrl}${url}`, {
// headers : fetchHeaders()
// }))).then( (responses) => {
// for(let res of responses) {
// if (res.headers.has('access-token') && res.status !== 304) {
// updateAccessToken(res.headers.get('access-token'))
// }
// }
// return Promise.all(responses.map( (response) => response.json().catch(err => {
// return {};
// })))
// }).then( (data) => {
// onSuccess(data)
// }).catch((error) => {
// onError(error)
// })
} }
export const validateGoogleLoginToken = (url, config, onSuccess, onError) => { export const validateGoogleLoginToken = (url, config, onSuccess, onError) => {
...@@ -282,7 +299,7 @@ export async function authentication (url, payload, onSuccess, onError) { ...@@ -282,7 +299,7 @@ export async function authentication (url, payload, onSuccess, onError) {
// } // }
// //
// sessionStorage.setItem('@portalmec/auth_headers', JSON.stringify(auth_headers)) // sessionStorage.setItem('@portalmec/auth_headers', JSON.stringify(auth_headers))
// //
// return response.json().catch(err => { // return response.json().catch(err => {
// return {}; // return {};
// }) // })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment