Created
May 18, 2022 12:51
-
-
Save drugoi/356576d7e1cdf328c5c3c13f55d5677d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const orders = []; | |
const fetchOrders = async (next = 1) => { | |
const response = await fetch( | |
`https://arbuz.kz/api/v1/order/list?page=${next}&limit=10`, | |
{ | |
headers: { | |
accept: "application/json, text/plain, */*", | |
}, | |
referrer: "https://arbuz.kz/ru/profile", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: null, | |
method: "GET", | |
mode: "cors", | |
credentials: "include", | |
} | |
); | |
const responseJson = await response.json(); | |
orders.push(...responseJson.data); | |
if ( | |
responseJson.page.next && | |
responseJson.page.next !== responseJson.page.current | |
) { | |
fetchOrders(responseJson.page.next); | |
} else { | |
console.log( | |
orders.reduce((sum, order) => { | |
return sum + order.amount; | |
}, 0) | |
); | |
} | |
}; | |
fetchOrders(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment