-
-
Save mohtada-h/418f03e5d2d719877517bb308ac9dd17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function () { | |
const token = JSON.parse(localStorage.getItem('user')).token; | |
const headers = new Headers(); | |
const url = 'https://web-api.snapp.ir/api/v1/ride/history'; | |
const query = '?page='; | |
let total = 0; | |
let page = 1; | |
headers.append('Authorization', token); | |
headers.append('Content-Type', 'application/json'); | |
while (true) { | |
const response = await fetch(`${url}${query}${page}`, { | |
method: 'GET', | |
headers | |
}); | |
const data = await response.json(); | |
if (data.rides.length === 0) { | |
break; | |
} | |
total += data.rides | |
.filter(it => it.latest_ride_status !== 6 && it.latest_ride_status !== 7) | |
.map(it => it.price) | |
.reduce((sum, price) => sum + price, 0); | |
page += 1; | |
} | |
console.log(total); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment